2017-02-01 7 views
0

私がしようとしているのは、ユーザーが画面をタップしたときに同じ位置に複数のスプライトを作成し、その間に遅延があり、前のノードの複数のノードをタップで重ねて作成する

ノードが作成されるとサイズが大きくなり、各ノードも異なる色になるので、最後に各ノードを見ることができるはずです。

これを動作させるために複数の異なる繰り返しを試しました。以下が最新です。

func createShape(location: CGPoint){ 
    var positionz:CGFloat = 1 

    for i in 1...6{ 
    let square = SKSpriteNode(color: randomColor(), size: CGSize(width: 40, height: 40)) 
    square.position = location 
    square.zPosition = positionz 
    addChild(square) 

    let shapeIncrease = SKAction.resize(toWidth: square.size.width + 50, height: square.size.height + 50, duration: 0.7) 
    let fadeOut = SKAction.fadeOut(withDuration:0.5) 
    //let remove = SKAction(square.removeFromParent()) 
    let shapeSequence = SKAction.sequence([shapeIncrease, fadeOut, SKAction.removeFromParent()]) 
square.run(shapeSequence) 
     positionz += 1 
     print("\(square.color)") 
    } 

} 

問題は、1つのノードしか見ることができないということです。ノードカウンタが増加し、各ノードの色が異なることが確認されましたが、正しく表示されるようにする方法はわかりません。

答えて

0

これを解決するために管理されています。同様のことをやろうとしている人のために、私はノードの作成を実行ブロックに入れてしまいました。

私はこれを行うのがはるかに優れたクリーナーの方法があると確信していますが、これは私のために働いているので、私はそれに固執するつもりです。

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 

    for touch in touches { 
     let location = touch.location(in: self) 
      let wait = SKAction.wait(forDuration: 0.15) 
     let s1 = SKAction.run { 
      self.createShape(location: location, zposition: 1) 
     } 
     let s2 = SKAction.run { 
      self.createShape(location: location, zposition: 2) 
     } 
     let s3 = SKAction.run { 
      self.createShape(location: location, zposition: 3) 
     } 
     let s4 = SKAction.run { 
      self.createShape(location: location, zposition: 4) 
     } 
     let s5 = SKAction.run { 
      self.createShape(location: location, zposition: 5) 
     } 
     let s6 = SKAction.run { 
      self.createShape(location: location, zposition: 6) 
     } 

      let sequence1 = SKAction.sequence([s1, wait, s2, wait, s3, wait, s4, wait, s5, wait, s6]) 
     run(sequence1) 
関連する問題