Ios cocos2d中更平滑的精灵旋转?
我有一个简单的程序,当你按住屏幕时,精灵向上移动,当你放开时,精灵向下移动。因此,在CCTouchesBegind函数中,我旋转精灵:Ios cocos2d中更平滑的精灵旋转?,ios,objective-c,cocos2d-iphone,Ios,Objective C,Cocos2d Iphone,我有一个简单的程序,当你按住屏幕时,精灵向上移动,当你放开时,精灵向下移动。因此,在CCTouchesBegind函数中,我旋转精灵: -(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ player.rotation = -5; } 然后在ccTouchesEnded函数中,我再次旋转它: -(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEven
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
player.rotation = -5;
}
然后在ccTouchesEnded函数中,我再次旋转它:
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
player.rotation = 20;
}
所以我想知道是否有办法让旋转变得更慢更平滑?当我运行它时,它看起来非常笨重,我希望它看起来更真实。我没有使用物理引擎(box2d、花栗鼠等)- 您可以使用CCRotateBy或CCRotateTo类函数来旋转它。 例如,玩家->运行动作(CCRotateTo::create(1.0f,-5));//在C中++ 这里第一个参数指定旋转的持续时间(当前为1秒),第二个参数指定角度 但是如果你太频繁地触摸屏幕,这个也可能看起来很奇怪
CCRotateBy *rotTouchBegin = [CCRotateBy actionWithDuration:1.0f angle:-5];
CCRotateBy *rotTouchEnd = [CCRotateBy actionWithDuration:1.0f angle:20];
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[player stopAllActions];
[player rotTouchBegin];
}
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[player stopAllActions];
[player rotTouchEnd];
}
如果你不想停止播放器上运行的所有动作,那么只需标记你的动作,以便使用
[player stopAction:[player getActionByTag:] 玩家是什么类型的对象?