简体   繁体   中英

Calling functions in SKAction.run doesn't work

func experiment() {
    print ("I am inside the function")
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    SKAction.run({self.experiment()})
}

Don't see the print happening.

That works, it will do nothing. All you are doing in that case is creating an action that runs a function. Since it does nothing, the action is released.

Now what you meant to do was run the action on the scene

run(SKAction.run({experiment()}))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM