swift - How to initial correctly between two class -
i want make sure in class home invoke class hud, , these 2 part code test okay when run in xcode, crash , show issue:
"fatal error: use of unimplemented initializer 'init(size:)' class 'leftbehind.hud'"
i hope told me how fixed it, thanks.
import uikit import spritekit class hud: skscene { let positionx:cgfloat let positiony:cgfloat let sceneself: skscene let year = sklabelnode() let month = sklabelnode() let day = sklabelnode() let hour = sklabelnode() let minute = sklabelnode() init(positionx:cgfloat,positiony:cgfloat,scene:skscene) { self.positionx = positionx self.positiony = positiony self.sceneself = scene super.init() } required init?(coder adecoder: nscoder) { fatalerror("init(coder:) has not been implemented") } func hudshow() { year.fontname = "arial" year.fontsize = 70 year.text = "this year" year.fontcolor = uicolor.whitecolor() year.position = cgpoint(x: positionx , y: positiony) sceneself.addchild(year) } }
below class invoke above class
import spritekit class home: skscene { override func didmovetoview(view: skview) { let hud = hud(positionx: frame.midx, positiony: frame.midy, scene: self) hud.hudshow() } }
edit: upload way work not perfect way want implement initial rather function refer.
instead of calling super.init()
call super.init(size size: cgsize)
you can use skview's bounds.size
property pass initializer.
Comments
Post a Comment