I'm trying to scale a CCSprite to any resolution in CocosSharp, this is what I've got:
void AddTruck ()
{
var spriteSheet = new CCSpriteSheet ("animations/truck.plist");
var animationFrames = spriteSheet.Frames.FindAll ((x) => x.TextureFilename.StartsWith ("frame"));
walkAnim = new CCAnimation (animationFrames, 0.1f);
walkRepeat = new CCRepeatForever (new CCAnimate (walkAnim));
truck = new CCSprite (animationFrames.First ()) { Name = "Truck" };
truck.Scale = 0.70f;
AddChild (truck);
}
And I want that when its added to scene, it be resized according to the device resolution... Any tips?
Thanks.
Well, I think that in order to do that, you have to have another folder with HD images, and acording to the device resolution, you use 'em... But I did the following, and it worked for me:
float ResTruck(CCSprite sprite)
{
float scale = 0.0f;
float resWid = CCScene.DefaultDesignResolutionSize.Width;
float resHei = CCScene.DefaultDesignResolutionSize.Height;
if (resWid > 500)
scale = 0.70f;
else if (resWid > 1080)
scale = 0.90f;
else if (resWid > 1300)
scale = 1.0f;
return scale;
}
And then, I asing the "scale" value to my sprite:
float scale = ResTruck(truck);
truck.Scale = scale;
And that's it :v