About Monkey 2 › Forums › Monkey 2 Programming Help › How can I control the framerate / How does the loop loops?
This topic contains 5 replies, has 4 voices, and was last updated by
Matthew Smith
2 years, 9 months ago.
-
AuthorPosts
-
July 8, 2016 at 9:53 am #1886
The FPS property is not assignable…
how can I control the framerate. Is it just waiting for VerticalBlank and dependent to my screen refresh rate?
I don’t really get the whole event loop of the AppInstannce/Window classes. Is there a link with a full explanation (more than the summary of the docs)?
I remember I read some things about fixed framerate and other things like that. I’ve also seen examples with the OnUpdate method in MX2 but can’t find it in the docs. What has really changed and how?
Is even there some eventloop if ‘App.RequestRender’ is not called?July 8, 2016 at 8:25 pm #1917<pre class=”lang:monkey decode:true ” title=”Framerate”>#Import “<std>”
#Import “<mojo>”Using std..
Using mojo..Global instance:AppInstance
Class MyWindow Extends Window
Field timer:Timer
Method New()
timer = New Timer(10,OnUpdate)
End MethodMethod OnUpdate()
If Keyboard.KeyReleased(Key.Escape) Then instance.Terminate()
App.RequestRender()
End MethodMethod OnRender( canvas:Canvas ) Override
canvas.DrawText(“FPS:”+App.FPS,0,0)
End MethodEnd Class
Function Main()
instance = New AppInstanceNew MyWindow
App.Run()
End Function
This I used to change the framerate. Using a timer.July 8, 2016 at 8:31 pm #1919The code insertion seems not to work? No idea what is happening.
July 8, 2016 at 11:55 pm #1931Sorry about that – more wordpress weirdness, should be fixed now.
July 9, 2016 at 10:57 am #1952Ok so OnUpdate (not documented yet) is a must in some situations…? May be I should wait for more complete docs before trying to understand the whole appInstance/window process.
July 9, 2016 at 11:30 am #1953@abakobo
No you don’t need to separate out your update (you can certainly as the above example shows). Put everything into the OnRender as follows:Monkey123456789101112Method OnRender(canvas:Canvas) Override'UpdateMyObjects.Update()'other things you wish to update'RenderApp.RequestRender()MyObjects.Render(canvas)'other things you wish to render'ie. scoreEndThis way the system handles everything – most of the available samples follow this example. You can create the OnUpdate timer if you want to update more regularly or at a specific rate.
That did catch me out initially trying to work through what was what.
-
AuthorPosts
You must be logged in to reply to this topic.