2016-10-11 11 views
3

スプライトが親から削除されると、関数を呼び出そうとしているので、スプライトは複製して再びシーンに入ることができます。
元のスプライトを親から削除してスプライトが重複する前に、現在のコードで毎回複製します。

はここに、これまでに私のコードです:SpriteKit:SKAction.sequence内の関数を呼び出す方法は?

import SpriteKit 


let plankName = "woodPlank" 

class PlankScene: SKScene { 

    var plankWood : SKSpriteNode? 

    var plankArray : [SKSpriteNode] = [] 

    override func didMove(to view: SKView) { 

    plankWood = childNode(withName: plankName) as? SKSpriteNode 


    let swipeRight : UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(PlankScene.swipedRight)) 

    swipeRight.direction = .right 

    view.addGestureRecognizer(swipeRight) 

    } 


    func swipedRight(sender: UISwipeGestureRecognizer) { 

    if sender.direction == .right { 

    let moveOffScreenRight = SKAction.moveTo(x: 400, duration: 0.5) 

    let nodeFinishedMoving = SKAction.removeFromParent() 

     plankWood?.run(SKAction.sequence([moveOffScreenRight, nodeFinishedMoving])) 


    } 
    //Functions To Be Call After Sequence Finishes 
    addPlank() 
    movePlanksUp() 


    } 


    func addPlank() { 
    let newPlank = plankWood?.copy() as! SKSpriteNode 
    newPlank.position = CGPoint(x: 0, y: -250) 
    plankArray.append(newPlank) 
    print(plankArray.count) 
    addChild(newPlank) 

    } 

    func movePlanksUp() { 
    for node:SKSpriteNode in plankArray { 
     node.run(SKAction.move(by: CGVector(dx: 0, dy: 250), duration: 0.10)) 
    } 
    } 


} 

答えて

1

完了

置き換える:

​​

で:

plankWood?.run(SKAction.sequence([moveOffScreenRight, nodeFinishedMoving]), 
    completion:{ 
     //Functions To Be Call After Sequence Finishes 
     addPlank() 
     movePlanksUp()}) 
関連する問題