代码之家  ›  专栏  ›  技术社区  ›  Matthew the Coder

在另一个循环内的循环中添加SKSpriteNode实例

  •  0
  • Matthew the Coder  · 技术社区  · 8 年前

    这是我正在沙盒应用程序中使用SpriteKit进行的代码实验。

    这是代码,但当我运行它时会崩溃。如果这一批要减少到1投,那么它就可以工作了。另外,如果我怀疑这与等待延迟和添加“石头”spritenode有关,但不确定是什么。

    for x in 1 ... 2 {
    
    if x == 1 {
    
    intStartIndex = 1
    intEndIndex = 3
    
        } else { 
    
    intStartIndex = 4
    intEndIndex = 5
    
        }
    
                run(SKAction.wait(forDuration: dblDelay)) {
    
                    for i in intStartIndex ... intEndIndex { 
                        print(i)
                        self.stone[i - 1].position = CGPoint(x: 0 , y: -100)
                        self.stone[i - 1].anchorPoint = CGPoint(x: 0.5, y: 0.5)
                        self.stone[i - 1].size = CGSize(width: 50, height: 50)
                        self.stone[i - 1].zPosition = 2
                        self.addChild(self.stone[i - 1])   
    
                        let actionMove = SKAction.move(to: CGPoint(x: 0, y: 0), duration: 0.3)
                        let actionRolling = SKAction.animate(with: stone[i - 1].arrayTexture, timePerFrame: 0.05)
                        let actionSequence = SKAction.sequence([actionMove,actionRolling])
                        stone[i - 1].run(actionSequence)
    
    
                    }
    
                }
                    dblDelay += 0.5
            }
    
    0 回复  |  直到 8 年前
    推荐文章