Stupid question about onUpdate and onRender

Monkey Forums/Monkey Programming/Stupid question about onUpdate and onRender

Uncle(Posted 2011) [#1]
Hello,

This may sound like a stupid question so bear with me. Are onUpdate and onRender invoked every cycle? I mean is onRender only called when its time to refresh the screen, and onUpdate called every time the SetUpdateRate trigger is fired? Could there be a difference between the number of times onUpdate is called vs onRender?

How is everyone working with these methods today? For example if you have a particle system are you doing all your updating of particle positions etc in the onUpdate method, and then just drawing them with the onRender method?

Cheers,

Unc


Shinkiro1(Posted 2011) [#2]

How is everyone working with these methods today? For example if you have a particle system are you doing all your updating of particle positions etc in the onUpdate method, and then just drawing them with the onRender method?


Yes that's the way to do it. Also it is a better design to seperate logic from rendering.

OnUpdate() is called as often as the UpdateRate is set (as you said). OnRender() is called as often as OnUpdate() with 1 exception: OnUpdate() is not executed as often as the UpdateRate is set, so monkey tries to catch up by calling OnUpdate() but skipping a few OnRender().


therevills(Posted 2011) [#3]
OnUpdate() is called as often as the UpdateRate is set (as you said). OnRender() is called as often as OnUpdate() with 1 exception: OnUpdate() is not executed as often as the UpdateRate is set, so monkey tries to catch up by calling OnUpdate() but skipping a few OnRender().



Think you mistyped one On* method there ;)

OnUpdate() is called as often as the UpdateRate is set (as you said). OnRender() is called as often as OnUpdate() with 1 exception: OnRender() is not executed as often as the UpdateRate is set, so monkey tries to catch up by calling OnUpdate() but skipping a few OnRender().


Uncle(Posted 2011) [#4]
Thanks guys :) Just wanted to make sure my logic was right before I dug myself into a big hole.


muddy_shoes(Posted 2011) [#5]
I posted an explanation here: http://monkeycoder.co.nz/Community/posts.php?topic=1017#8788 .

How best to work with the calls is going to depend on the nature of your game, the relative costs of your logic versus rendering and the variation of those costs from frame to frame.

For example, if you're writing an action game where it's possible to trigger events (explosions or whatever) that extend your update calculations then you may well find that the mojo update strategy is less than ideal as it exaggerates the framerate hit.