SKAction lock with arguments

I am trying to implement the following functions in my game. I run an action on a node sprite (sprite node parent is nil) and the action should wait for my specified time and then add the node to itself. I could not find any action that adds node to the parent. I was thinking of doing something like this:

node.runAction(SKAction.sequence([SKAction.waitForDuration(timetowait), SKAction.runBlock(addToSelf(node))]))

and just having a method like this:

func addToSelf(node: SKSpriteNode){
    self.addChild(node)
}

If I manage to do this, game performance will improve. Does anyone know if there is work around?

+4
source share
1 answer

You are on the right track. You should be able to use

SKAction.runBlock({ self.someFunction(param) })

See the documentation for more details .

+4
source

All Articles