我如何制作运行块动作 Swift SpriteKit

How do I Make a run block action Swift SpriteKit

你好,我已经尝试了很长时间,我正在使用 Swift SpriteKit,我的问题是我需要为一个节点做一个 runBlock 动作我如何做一个运行的动作我试过这个功能:

        var a = SKAction.runBlock({() in self.spawn1()})

供您参考 spawn1 是函数。
提前致谢!

这是我的代码,以帮助第一个答案的评论:

//
//  PlaysScene.swift
//  Pocket Rocket3
//
//  Created by Lucas Farleigh on 27/11/2014.
//  Copyright (c) 2014 Lucas Farleigh. All rights reserved.
//

import spriteKit

class PlayScene:SKScene {
    //declaring the node in this scene!
    let background = SKSpriteNode(imageNamed: "background")

    let bar1 = SKSpriteNode(imageNamed:"bar1")

    let bar2 = SKSpriteNode(imageNamed:"bar2")

    let bar3 = SKSpriteNode(imageNamed:"bar3")

    let bar4 = SKSpriteNode(imageNamed:"bar4")

    let bar5 = SKSpriteNode(imageNamed:"bar5")

    let bar6a = SKSpriteNode(imageNamed: "bar6")
    let bar6b = SKSpriteNode(imageNamed: "bar6")

    let bar6c = SKSpriteNode(imageNamed: "bar6")
    let bar6d = SKSpriteNode(imageNamed: "bar6")

    let bar6e = SKSpriteNode(imageNamed: "bar6")
    let bar6f = SKSpriteNode(imageNamed: "bar6")

    let bar6g = SKSpriteNode(imageNamed: "bar6")
    let bar6h = SKSpriteNode(imageNamed: "bar6")

    let bar6i = SKSpriteNode(imageNamed: "bar6")
    let bar6j = SKSpriteNode(imageNamed: "bar6")
    //making actions

    override func didMoveToView(view: SKView) {


        var actionmove = SKAction.moveToY(0, duration: 15)
        var delay = SKAction.waitForDuration(NSTimeInterval(1.5))
        var delchild = SKAction.removeFromParent()

        func spawn1(){
            bar6a.position = CGPointMake(800 ,CGRectGetMaxY(self.frame))
            bar6b.position = CGPointMake(1600,CGRectGetMaxY(self.frame))
            addChild(bar6a)
            addChild(bar6b)


        }
        func spawn2 (){
            bar6c.position = CGPointMake(400 ,CGRectGetMaxY(self.frame))
            bar6d.position = CGPointMake(1200,CGRectGetMaxY(self.frame))
            addChild(bar6c)
            addChild(bar6d)


        }
        func spawn3 (){
            bar6e.position = CGPointMake(600 ,CGRectGetMaxY(self.frame))
            bar6f.position = CGPointMake(1400,CGRectGetMaxY(self.frame))
            addChild(bar6e)
            addChild(bar6f)


        }
        func spawn4 (){
            bar6g.position = CGPointMake(700 ,CGRectGetMaxY(self.frame))
            bar6h.position = CGPointMake(1500,CGRectGetMaxY(self.frame))
            addChild(bar6g)
            addChild(bar6h)


        }

        func spawn5 (){
            bar6i.position = CGPointMake(700 ,CGRectGetMaxY(self.frame))
            bar6j.position = CGPointMake(1500,CGRectGetMaxY(self.frame))
            addChild(bar6i)
            addChild(bar6j)


        }
        var a = SKAction.runBlock({ self.spawn1() })
        var b = SKAction.runBlock(spawn2)
        var c = SKAction.runBlock(spawn3)
        var d = SKAction.runBlock(spawn4)
        var e = SKAction.runBlock(spawn5)



        var delayA = SKAction.waitForDuration(NSTimeInterval(1.5))
        var delayB = SKAction.waitForDuration(NSTimeInterval(2))
        var delayC = SKAction.waitForDuration(NSTimeInterval(4))
        var delayD = SKAction.waitForDuration(NSTimeInterval(6))
        var delayE = SKAction.waitForDuration(NSTimeInterval(8))

        var sequence1 = SKAction.sequence([delayA,a,actionmove,delchild])
        var sequence2 = SKAction.sequence([delayB,b,actionmove,delchild])
        var sequence3 = SKAction.sequence([delayC,c,actionmove,delchild])
        var sequence4 = SKAction.sequence([delayD,d,actionmove,delchild])
        var sequence5 = SKAction.sequence([delayE,e,actionmove,delchild])

        var repeat1 = SKAction.repeatActionForever(sequence1)
        var repeat2 = SKAction.repeatActionForever(sequence2)
        var repeat3 = SKAction.repeatActionForever(sequence3)
        var repeat4 = SKAction.repeatActionForever(sequence4)
        var repeat5 = SKAction.repeatActionForever(sequence5)


        //actionmove: making it smooth
        actionmove.timingMode = SKActionTimingMode.EaseOut

        //doing stuff with the background
        background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
       background.yScale = 10.0
        background.xScale = 10.0

        addChild(background)

        //running the actions
        bar6a.runAction(repeat1)
        bar6b.runAction(repeat1)
        bar6c.runAction(repeat2)
        bar6d.runAction(repeat2)
        bar6e.runAction(repeat3)
        bar6f.runAction(repeat3)
        bar6g.runAction(repeat4)
        bar6h.runAction(repeat4)
        bar6i.runAction(repeat5)
        bar6j.runAction(repeat5)



    }

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {



    }
}
var a = SKAction.runBlock({ self.spawn1() })
yournode.runAction(a)