菜鸟教程小白 发表于 2022-12-11 18:49:48

ios - 如何在 Sprite Kit 中跟踪动画


                                            <p><p>我需要跟踪带有纹理的动画。我正在为电源栏设置动画,当用户单击屏幕时,它应该停止并节省电量。我不知道如何节省电力。到目前为止,我有这个:第一次触摸电源条动画,但在第二次触摸时它只会停止但不会节省电量。</p>

<p>这就是我创建动画的方式:</p>

<pre><code>textureAtlas = SKTextureAtlas(named:&#34;images&#34;)
      for i in 1...textureAtlas.textureNames.count{
            let name = &#34;\(i).png&#34;
            textureArray.append(SKTexture(imageNamed: name))
      }
let animateForward = SKAction.animate(with: textureArray, timePerFrame: 0.1)
      let animateBackward = SKAction.reversed(animateForward)
      let sequence = SKAction.sequence()
</code></pre>

<p>这是我检测触摸的方式:</p>

<pre><code>override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
    if let firstTouchStorage = touches.first{ // after first touch
      let animateForward = SKAction.animate(with: textureArray, timePerFrame: 0.1)
      let animateBackward = SKAction.reversed(animateForward)
      let sequence = SKAction.sequence()
      arrow.removeAllActions()
      arrow.run(SKAction.repeatForever(sequence))
      firstTouch = firstTouchStorage
    }
    for touch in touches{
      if touch == firstTouch{
            touchesArray.append(touch)

            let angle = arrow.zRotation
            if touchesArray.count == 2{
                arrow.removeAllActions()
                arrow.removeFromParent()
            }
      }
    }
</code></pre>

<p>我试图解决这个问题太久了,但我想不通。我希望你能帮助我。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>正如@KnightOfDragon 建议的那样:animateWithTextures 有一个 restore: 参数,如果您将其设置为 false,那么当您停止动画时,最后一个纹理应该保留在 Sprite 上。如果你继续阅读纹理描述,那么你就会知道它停在什么纹理上,并可以相应地进行计划</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在 Sprite Kit 中跟踪动画,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/42008897/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/42008897/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在 Sprite Kit 中跟踪动画