菜鸟教程小白 发表于 2022-12-13 04:22:48

ios - Spritebuilder 如何以编程方式更改 CCNode 的动画(CCB 文件)?


                                            <p><p>我正在尝试制作一个 Spritebuilder iPhone 游戏,我的主要角色 _player 是一个 CCNode,其子节点是一个 CCBFile,其中包含角色的空闲动画。</p>

<p>我想将这个 _player 的 CCBFile 更改为另一个名为 ForwardDash.ccbi 的 CCBFile,其中包含玩家触摸屏幕时的“攻击”动画。</p>

<p>这就是我正在尝试的:</p>

<pre><code> //_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;
         CCNode *animar = ;
         ;
</code></pre>

<p>它失败并给我错误:'Thread 1: signal SIGABRT'</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>setSpriteFrame 不是您正在寻找的方法。如果您想保留当前的 ​​CCB 设置,您应该能够通过以下方式完成您想要的:</p>

<pre><code>CCSprite *wat = _player.children;
;
CCNode *animar = ;
;
</code></pre>

<p>虽然这可行,但我建议您尝试利用 SpriteBuilder 中的不同动画时间线。您可以将新时间线添加到 CCB 文件,然后以编程方式更改动画,而无需删除和添加新节点。您可以阅读更多关于使用时间线的信息 <a href="https://www.makeschool.com/tutorials/getting-started-with-spritebuilder/sprite-animation-spritebuilder/" rel="noreferrer noopener nofollow">here</a> .设置完成后,您可以使用以下命令开始新动画:</p>

<pre><code>CCSprite *wat = _player.children;
CCAnimationManager* animationManager = wat.animationManager;
;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Spritebuilder 如何以编程方式更改 CCNode 的动画(CCB 文件)?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/27685498/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/27685498/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Spritebuilder 如何以编程方式更改 CCNode 的动画(CCB 文件)?