开发者

Scale sprite according rotation. How to calculate it correctly for my situation? [Math-iphone-cocos2d]

At first: I'm using cocos2d for iphone. But this isn't so important for this question.

My problem is now...I want to scale a sprite on the Y axis. I can do that with this function:

mySprite.scaleY = myFloatValue;

I want to set the scaleY value related to the rotation of the sprite..

Some cases:

If the rotation is 0, scaleY is 0. If the rotation is 90, scaleY is 1. If the rotation is 180 scaleY is 0 If the rotation is 360 scaleY is 0. If the rotation is 45 scaleY is 0.5.

Some more explanation: If my sprite is vertical the scaleY value is 1. If my sprite is horizontal the scaleY value is 0.

And I need a forumula for this.

I got it working for the angles between 0 and 90:

mySprite.scaleY = rotation/90.0f;

From the angles between 90 and 180 teh开发者_如何学C scaleY should go from 1.0 to 0.0f

I want to make a smooth scaling..

Btw, did you understood what I want? If not I could make a video or some screenshots..


How about mySprite.scaleY = sinf(rotation);

EDIT:

To make it always positive

mySprite.scaleY = fabs(sinf(rotation));

Where rotation is in radians

mySprite.scaleY = fabs(sinf(M_PI * rotation / 180));

Where rotation is in degrees

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜