菜鸟教程小白 发表于 2022-12-12 12:13:58

ios - 停止/暂停在 SpriteKit Swift 3 中设置为永远重复的声音


                                            <p><p>我遇到了一个问题,如果有人能提供帮助,我真的很高兴,基本上我有两个声音序列,它们将永远重复。但是,我想要它,以便我可以触发声音停止。</p>

<p>我真正需要知道的是:</p>

<p>在 Swift 3 SpriteKit 中,我使用什么代码来无限期地停止或暂停重复的声音序列?</p>

<p>编辑:我使用 SKActions 播放声音,现在问题已解决。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在堆栈溢出时显示一些代码总是好的做法,对于您当前的问题,我们只能猜测。</p>

<p>如果您将 SKActions 用于声音,您可以为重复 Action 指定一个键,然后稍后删除该 Action 。像这样创建 key </p>

<pre><code> class GameScene: SKScene {

       let soundKey = &#34;RemoveSoundKey&#34; // this avoids typos
}
</code></pre>

<p>然后将您的操作更改为此</p>

<pre><code> let repeatAction = SKAction.repeatActionForever(YOURSOUNDACTION)
run(repeatAction, withKey: soundKey)
</code></pre>

<p>比你说的多</p>

<pre><code> removeAction(forKey: soundKey)
</code></pre>

<p>当你想停止重复 Action 时。</p>

<p>注意:如果您在节点上运行操作,例如</p>

<pre><code> player.run(repeatAction...)
</code></pre>

<p>不要忘记在节点上调用删除操作</p>

<pre><code> player.removeAction(forKey: soundKey)
</code></pre>

<p>希望对你有帮助</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 停止/暂停在 SpriteKit Swift 3 中设置为永远重复的声音,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39856752/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39856752/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 停止/暂停在 SpriteKit Swift 3 中设置为永远重复的声音