将 CCSprite 缩放到精确大小 [英] Scale CCSprite to exact size
本文介绍了将 CCSprite 缩放到精确大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将精灵缩放到精确大小的最佳技术是什么.scale 属性是一个乘数,但是如果你想让一个精灵正好是 X 像素宽,有没有简单的技术?或者,它是否需要简单地使用所需的大小和精灵的实际 contentsize
来计算必要的 scale
操作?
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 technique? Or, would it require simply using the desired size and the sprites actual contentsize
to calculate the necessary scale
operation?
推荐答案
我相信这是可行的:
-(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];
这篇关于将 CCSprite 缩放到精确大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文