cocoa touch - touchesBegan function in Swift doesn't need override -
i'm new xcode , i've been playing around making spritekit game in swift.
in every tutorial or stack overflow topic i've looked at, touchesbegan function has override before it, when copy code gamescene.swift, error, "override can specified on class members," auto-fix of deleting "override."
so instead of this:override func touchesbegan(touches: set<nsobject>, withevent event: uievent) {...}
wants me have this:func touchesbegan(touches: set<nsobject>, withevent event: uievent) {...}
i'm not sure why happening, , don't know if affect how function works.
my current code in gamescene.swift is:
import spritekit class gamescene: skscene { required init?(coder adecoder: nscoder) { super.init(coder: adecoder) } override init(size: cgsize) { super.init(size: size) backgroundcolor = skcolor.blackcolor() let stars = stars() var starnode:sknode! starnode = stars.createstars(cgfloat(30), direction: 1, scalex: self.frame.width, scaley: self.frame.height) addchild(starnode) func touchesbegan(touches: set<nsobject>, withevent event: uievent) { //nothing here yet } } }
is there else missing?
thanks!
you must close second init }
after addchild(starnode)
. code should read:
import spritekit class gamescene: skscene { required init?(coder adecoder: nscoder) { super.init(coder: adecoder) } override init(size: cgsize) { super.init(size: size) backgroundcolor = skcolor.blackcolor() // let stars = stars() var starnode:sknode! starnode = stars.createstars(cgfloat(30), direction: 1, scalex: self.frame.width, scaley: self.frame.height) addchild(starnode) } override func touchesbegan(touches: set<nsobject>, withevent event: uievent) { //nothing here yet } }
Comments
Post a Comment