将精灵缩放到精确大小的最佳技术是什么. scale属性是一个乘数,但是如果你想要一个sprite正好是X像素宽,那么有一种简单的技术吗?或者,它是否需要简单地使用所需的大小和精灵实际内容来计算必要的比例操作?
我相信这有效:
- -(void)resizeSprite:(CCSprite*)sprite toWidth:(float)width toHeight:(float)height {
- sprite.scaleX = width / sprite.contentSize.width;
- sprite.scaleY = height / sprite.contentSize.height;
- }
把它放在你的游戏中,并使用如下:
- [self resizeSprite:mySprite toWidth:350 toHeight:400];