我正在尝试制作一个Spritebuilder iPhone游戏,我的主要角色_player是一个CCNode,它的子角色是一个CCBFile,它保存角色的空闲动画。
我想将此_ player的CCBFile更改为另一个名为ForwardDash.ccbi的CCBFile,当播放器触摸屏幕时,它包含‘攻击’动画。
这就是我想要的:
//_player is a CCNode, its first child is the CCBFile with the idle animation.
//animar is a pointer to the CCBFile with the ForwardDash animation
CCSprite *wat = _player.children[0];
CCNode *animar = [CCBReader load:@"ForwardDash"];
[wat setSpriteFrame: (CCSpriteFrame*)animar];它失败,并给出了错误:‘线程1:信号SIGABRT’
发布于 2015-01-09 00:44:51
setSpriteFrame不是您正在寻找的方法。如果您希望保持当前的CCB设置,您应该能够通过执行以下操作来完成所需的任务:
CCSprite *wat = _player.children[0];
[wat removeFromParent];
CCNode *animar = [CCBReader load:@"ForwardDash"];
[_player addChild:animar];虽然这样做有效,但我建议您尝试利用SpriteBuilder中不同的动画时间线。您可以向CCB文件添加新的时间线,然后以编程方式更改动画,而无需删除和添加新节点。您可以阅读更多关于使用时间线这里的内容。一旦设置好,您就可以使用以下内容启动一个新的动画:
CCSprite *wat = _player.children[0];
CCAnimationManager* animationManager = wat.animationManager;
[animationManager runAnimationsForSequenceNamed:@"ForwardDash"];https://stackoverflow.com/questions/27685498
复制相似问题