我有一个角色类别,其中有 CCSprite 变量。触摸按钮或跳跃后,角色正在移动到点并动画步行动画,一切正常,但动画后 CCSprite 的帧很差(步行帧之一)。在我的更新函数结束时,我编写了这段代码,但随后它就像卡住一样,角色无法跳跃或行走更多,运行 Action 的数量始终为1:
if(this.sprite.numberOfRunningActions() == 0){
if(this.state != CharacterState.IDLE){
this.changeState(CharacterState.IDLE); // without this row it works still fine
}
}
更改状态函数:
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; }
关于java - 如何设置CCSprite的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16345154/