缩放CCSprite到精确大小 [英] Scale CCSprite to exact size

查看:368
本文介绍了缩放CCSprite到精确大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是将精灵缩放到精确尺寸的最佳技术。 scale属性是一个乘数,但是如果你想要一个精灵是X像素宽,有没有一个简单的技术?或者,是否需要简单地使用所需的大小和sprites实际 contentsize 来计算必要的 scale 操作? p>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆