xcode - SceneKit Update Method for Physics Simulation -
i have played sprite kit , have used update method set things process each time step. i'm trying learn swift scene kit , can't seem find equivalent.
can point me example of implementing update method scenekit? thanks.
(yes, know question scenekit, not spritekit, touches on commonalities , differences between 2 frameworks, i'll address in answer.)
in spritekit, game-loop methods (update
, didsimulatephysics
, etc) part of scene class skscene
. isn't best idea, though — might want treat scene instance more data place implement game logic (especially scenes can built in xcode 6 graphical scene editor). in ios 8 , os x yosemite, methods in 2 places. if you're subclassing skscene
per-frame game logic, can keep doing that. if you'd rather put code elsewhere, can set delegate on scene, , implement equivalent skscenedelegate
methods there.
scenekit has more of separation of concerns. scnscene
closer being pure data-model object, , rendering-loop functionality managed view (or other object) responsible displaying scene. typically display scene in scnview
— there other classes can render scenes, too, common api found in scnscenerenderer
protocol. use delegate
property defined protocol set delegate view, , in delegate can implement scnscenerendererdelegate
methods participate in key phases of render loop.
the scenekit loop phases correspond directly in spritekit: update:
becomes renderer:updateattime:
, didevaluateactions:
becomes renderer:didapplyanimationsattime:
(because includes coreanimation-style animations spritekit-style actions), etc.
so, scenekit equivalent of spritekit per-frame update
method, this:
set 1 of custom objects (say, view controller)
delegate
ofscnview
instance.in custom class, implement following method:
func renderer(_ arenderer: scnscenerenderer!, updateattime time: nstimeinterval) { // per-frame code here }
or similar other scnscenerendererdelegate
methods if per-frame logic needs happen after actions or physics have been processed.
Comments
Post a Comment