objective c - SCNScene - Not rendering changes to SKNode made on touchesBegan handler -
i'm subclassing sknode , implemening touchbegan handler.
when user clicks on node, node position changed node not move on screen.
i guess need force rendering of skscene somehow.
to test did following minor changes template games of xcode6. here changes template:
gameviewcontroler.swift
let hud = skscene(filenamed: "hud.sks") scnview.overlayskscene = hud var customnode = customnode() customnode.text = "touch here" customnode.position = cgpointmake(200, 200); hud.addchild(customnode)
new class customenode.swift
import foundation import spritekit public class customnode:sklabelnode{ public override init() { super.init(); userinteractionenabled = true; } public required init(coder adecoder: nscoder) { fatalerror("init(coder:) has not been implemented") } public override func touchesbegan(touches: nsset, withevent event: uievent) { position.y = (position.y + 100) % 300 + 100; //does not update on screen }
}
if add action ship works:
let ship = scene.rootnode.childnodewithname("ship", recursively: true)! ship.runaction(scnaction.repeatactionforever(scnaction.rotatebyx(0, y: 2, z: 0, duration: 1)))
how force rendering?
update clarify complete code of gameviewcontroler.swift, removing everthing not needed.
import uikit import quartzcore import scenekit import spritekit class gameviewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() // create new scene let scene = scnscene(named: "art.scnassets/ship.dae") //comes xcode6 game project template. // create , add camera scene let cameranode = scnnode() cameranode.camera = scncamera() scene?.rootnode.addchildnode(cameranode) // place camera cameranode.position = scnvector3(x: 0, y: 0, z: 15) // retrieve scnview let scnview = self.view scnview // set scene view scnview.scene = scene // allows user manipulate camera scnview.allowscameracontrol = true // configure view scnview.backgroundcolor = uicolor.blackcolor() let hud = skscene(size: self.view.bounds.size) scnview.overlayskscene = hud scnview.overlayskscene.userinteractionenabled = true; var customnode = customnode() customnode.text = "touch here" customnode.position = cgpointmake(200, 200); hud.addchild(customnode) //let ship = scene.rootnode.childnodewithname("ship", recursively: true)! //ship.runaction(scnaction.repeatactionforever(scnaction.rotatebyx(0, y: 2, z: 0, duration: 1))) } }
simple add @ viewdidload bottom:
scnview.play(nil)
Comments
Post a Comment