Scale CCSprite to exact size

后端 未结 2 665
太阳男子
太阳男子 2021-01-05 08:22

What is the best technique to scale a sprite to an exact size. The scale property is a multiplier, but if you want a sprite to be exactly X pixels wide, is there a simple te

相关标签:
2条回答
  • 2021-01-05 08:53

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

    hpBarSprite.scaleX = hpCurrent / hpMax ;

    0 讨论(0)
  • 2021-01-05 09:00

    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 like this:

    [self resizeSprite:mySprite toWidth:350 toHeight:400];
    
    0 讨论(0)
提交回复
热议问题