Alex Pilugin Alex Pilugin - 6 months ago 52
Swift Question

Swift. SpriteKit. Any example of customAction withDuration = run block of code with duration

Could you provide any example of code how to create and use customAction withDuration. Thanks.

P.s. For whom who add minuses to my question. I wanted to have SKAction "run block with duration" I visited Apple API Reference but found another opportunity with the same purpose "customAction withDuration". I asked this question because I never used it and didn't find any example of use it.


You can try something like this:

let action = SKAction.customAction(withDuration: 1) { (aNode, 0.3) in
    //do whatever you want here

Here, you are creating a variable called action with type SKAction. The duration of the action is 1 second, the node that you are using is called aNode, and the block is occurring 0.3 seconds in to the action.