繁体   English   中英

SKAction.animation-帧顺序

[英]SKAction.animation - frame order

А引起意外的问题:

let jaba = SKSpriteNode (imageNamed: "jaba0")
let jabaAnimationThrow: SKAction

for i in 0...1 {
        texturesJaba.append(SKTexture(imageNamed: "jaba\(i)"))
    }
    jabaAnimationThrow = SKAction.animate(with: texturesJaba,
                                         timePerFrame: 0.30)
func enemyThrow(enemy: SKSpriteNode) { 
    let enemyRun = (SKAction.repeatForever((SKAction.sequence([SKAction.wait(forDuration: 3, withRange: 2),jabaAnimationThrow]))))
enemy.run(enemyRun)} 
enemyThrow(enemy: jaba)

问题:SCAstion.animation首先播放第1帧“ jaba1”,然后播放第0帧“ jaba0”! 为什么?

谢谢!

我已经编译了您的代码,并且效果很好。 步骤如下:

  1. 在您的GameScene.swift文件中,按照以下步骤设置jaba Player

     override func didMove(to view: SKView) { let jaba = SKSpriteNode (imageNamed: "jaba0") jaba.position = CGPoint(x: 100, y: 200) // set your desired position jaba.setScale(0.2) // whatever scale you might need self.addChild(jaba) } 
  2. 之后,如下所示在GameScene.swift文件中使敌人投掷(敌人:SKSpriteNode)函数

     func enemyThrow(enemy: SKSpriteNode) { var texturesJaba = [SKTexture]() let jabaAnimationThrow: SKAction for i in 0...1 { texturesJaba.append(SKTexture(imageNamed: "jaba\\(i)")) } jabaAnimationThrow = SKAction.animate(with: texturesJaba, timePerFrame: 0.30) let enemyRun = (SKAction.repeatForever((SKAction.sequence([SKAction.wait(forDuration: 3, withRange: 2),jabaAnimationThrow])))) enemy.run(enemyRun) } 
  3. 最后,在didMove(toView :)函数中,在self.addchild(jaba)之后调用敌人Throw(enemy :)函数。 该代码应如下所示:

      override func didMove(to view: SKView) { let jaba = SKSpriteNode (imageNamed: "jaba0") jaba.position = CGPoint(x: 100, y: 200) // set your desired position jaba.setScale(0.2) // whatever scale you might need self.addChild(jaba) // call the function enemyThrow here enemyThrow(enemy: jaba) } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM