ios - How can I call a method from another swift file in GameViewController? -
i have button have created in storyboard lives on game game screen. has ib action in gameviewcontroller() follows:
@ibaction func buttonpressed(sender: anyobject) { gamescene().mycustommethod() }
in gamescene lives mycustommethod() spawn enemies, code above doesn't work properly. if add println("button pressed")
in ibaction, print out in console mycustommethod won't execute , spawn enemies expected.
can me or explain how resolve issue? thanks
in method, create new gamescene
object each time. should create once (at initialization), , call mycustommethod
on object.
var gamescene: gamescene! override func viewdidload() { gamescene = gamescene() } @ibaction func buttonpressed(sender: anyobject) { gamescene.mycustommethod() }
Comments
Post a Comment