ios - Swift: Can't subclass SCNNode? Fatalerror -
ok, need subclass scnnode because have different scnnodes different "abilities" in game (i know people don't subclass scnnode need to)
i have followed every other question subclassing scnnode , creating subclass of scnnode continue error:
fatal error: use of unimplemented initializer 'init()' class 'littledude.dude'
where dude
name of scnnode subclass.
following second question, because of classing issues how attempt scnnode .dae scene , assign dude()
:
var thedude = dude(geometry: scnsphere(radius: 0.1)) //random geometry first var modelscene = scnscene(named: "art.scnassets/ryderfinal3.dae")! if let d = modelscene.rootnode.childnodes.first { thedude.transform = d.transform thedude.geometry = d.geometry thedude.rotation = d.rotation thedude.position = d.position thedude.boundingbox = d.boundingbox thedude.geometry?.firstmaterial = d.geometry?.firstmaterial } print("dude: ", thedude)
then in dude class:
class dude: scnnode { init(geometry: scngeometry) { super.init() center(node: self) self.scale = scnvector3(x: modifier, y: modifier, z: modifier) //thedude.transform = scnmatrix4mult(thedude.transform, scnmatrix4makerotation(360, 0, 1, 0)) //thedude.worldorientation = . //self.thedude.position = scnvector3make(0, 0, -1) s in animscenes { if let anim = animationfromscenenamed(path: s) { animations.append(anim) anim.usesscenetimebase = true anim.repeatcount = float.infinity self.addanimation(anim, forkey: anim.description) } } } /* xcode required */ required init(coder adecoder: nscoder) { fatalerror("init(coder:) has not been implemented222") }
the error gets drawn on first line of custom class , happens when try clone , add custom scnnode scene:
func makedude(hitposition: scnvector3) { //print("dude") let clone = thedude.clone() as? scnnode clone?.position = hitposition self.sceneview.scene.rootnode.addchildnode(clone!) }
even though cast scnnode try avoid error. how can clone , use custom scnnode in scene? wrong here?
if subclass scnnode , override initializer init(geometry: scngeometry?)
you'll need call same initalizer of super during init. try changing
super.init()
to
super.init(geometry: geometry)
Comments
Post a Comment