Is 30 fps OnRender() with 60 fps OnUpdate() doable

Monkey Targets Forums/Flash/Is 30 fps OnRender() with 60 fps OnUpdate() doable

retroX(Posted 2014) [#1]
To get good touch input at 60 fps in OnUpdate() and better animation at 30 fps in OnRender() for low CPU powered devices, is there a way to set games at 60 fps but skip OnRender() half of the time?


ziggy(Posted 2014) [#2]
If you set the UpdateRate to 60, Monkey will make it's best to call 60 updates per second and, as many as possible (30?) renders per second, depending on hardware. So, it's not only possible but, in fact, it's the way Monkey works.

If you set UpdateRate(60), it will update at 60 FPS and render as close as possible to 60 FPS. If the closest it can get is 30FPS, it'll be rendered at 30 FPS, while keeping updates at 60.


Danilo(Posted 2014) [#3]
is there a way to set games at 60 fps but skip OnRender() half of the time?

Try this if you want it for Flash target (has problems with GLFW):
Import mojo

Class Game Extends App

    Method OnCreate:Int()
        SetUpdateRate(60)
        Return 0
    End
    
    Method OnUpdate:Int()
        counter_1 += 1
        If KeyHit(KEY_ESCAPE) Then EndApp
        Return 0
    End
    
    Method OnRender:Int()
        skip_render ~= 1
        If skip_render Then Return 0

        counter_2 += 1

        ' rendering...
        Cls(64,64,64)
        DrawText(String(counter_1),10,10)
        DrawText(String(counter_2),10,30)

        Return 0
    End
    Private
        Field skip_render:Int = 0

        Field counter_1:Int
        Field counter_2:Int
End


Function Main:Int()
    New Game
    Return 0
End

counter_1 and counter_2 are just for testing. You just need the skip_render stuff in OnRender().


retroX(Posted 2014) [#4]
Thanks for the useful info.


navyRod(Posted 2014) [#5]
tried this

html5,flash,android -- work

GLFW,W8 -- displaying flashing background here.


ziggy(Posted 2014) [#6]
Yes, you can't avoid renders on GLFW as the backbuffer is not warrantied to keep it's contents after every frame.
But, honestly, as I said in the first answer, you don't need this. Monkey does already adjust rendering and updating for you.
SetUpdateRate(60) means:
Call update 60 times per second
Call render as closely as 60 times per second, if the hardware allows it, and the rendering is not too slow.

In case the rendering is too slow, or the machine can't support 60 Hhz on screen device, you'll get more updates than renders per second, so the logic of the game is kept. If you SetUpdateRate(60) on a device that only supports 30FPS, you'll get two updates for every render.

I think that's what you where trying to achieve and the good news is that you don't need to do it. It's already designed this way.