我有一个字符类,其中是CCSprite变量。在触摸按钮或跳跃后,角色移动到指向并动画行走动画,一切正常,但动画CCSprite的帧不好(行走帧之一)。在更新功能的最后,我编写了这段代码,但是就像冻结,角色无法跳跃或行走一样,正在执行的操作数始终为1:
if(this.sprite.numberOfRunningActions() == 0){
if(this.state != CharacterState.IDLE){
this.changeState(CharacterState.IDLE); // without this row it works still fine
}
}
changeState函数:
public void changeState(CharacterState state){
sprite.stopAllActions();
this.state = state;
switch(state){
case IDLE:{ this.sprite = CCSprite.sprite(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("Player.png")); break;}
case WALK_LEFT:{ this.sprite.runAction(wAction); break; }
.
.
.
最佳答案
好吧,我一个人解决了。 :)
我创建了CCSpriteFrame类型的类变量。
CCSpriteFrame frame_idle;
在类构造函数中:
frame_idle = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("Player.png");
并将案例IDLE更改为:
case IDLE:{ this.sprite.setDisplayFrame(frame_idle); break; }