Scale CCSprite to exact size

What is the best way to scale a sprite to its exact size. The scale property is a multiplier, but if you want the sprite to be exactly at X pixels, is there a simple technique? Or would you just need to use the right size and actual contentsize sprites to calculate the required scale operation?

+7
source share
2 answers

I believe this works:

 -(void)resizeSprite:(CCSprite*)sprite toWidth:(float)width toHeight:(float)height { sprite.scaleX = width / sprite.contentSize.width; sprite.scaleY = height / sprite.contentSize.height; } 

Put it in your game and use it like this:

 [self resizeSprite:mySprite toWidth:350 toHeight:400]; 
+19
source

You can use these two properties: scaleX and scaleY. for example, use in the HP panel.

hpBarSprite.scaleX = hpCurrent / hpMax;

0
source

All Articles