About Monkey 2 › Forums › Monkey 2 Programming Help › Question to App.RequestRender()
This topic contains 11 replies, has 5 voices, and was last updated by
c0d3r9
8 months, 4 weeks ago.
-
AuthorPosts
-
July 17, 2018 at 12:45 am #15065
App.RequestRender() renders the scene, right?
Canvas things are called after that.
Lights too?
Why?Here is the code from the simplelightning example and App.RequestRender() is in the middle of that.
Maybe anybody can say me why?Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748Method OnRender( canvas:Canvas ) OverrideGlobal viewRot:=0.0viewRot+=.001canvas.Translate( Width/2,Height/2 )canvas.Scale( Sin( viewRot*3 )*.25+1.25,Cos( viewRot*5 )*.25+1.25 )canvas.Rotate( viewRot )canvas.Translate( -Width/2,-Height/2 )Local rmouse:=-canvas.Matrix * Mouse.LocationGlobal lightRot:=0.0lightRot+=.02App.RequestRender()canvas.AmbientLight=Color.DarkGreycanvas.BeginLighting()canvas.AddLight( _light,rmouse.X,rmouse.Y,lightRot )canvas.AddLight( _light,rmouse.X,rmouse.Y,lightRot+Pi )canvas.AddLight( _light,rmouse.X,rmouse.Y,lightRot+Pi/2 )canvas.AddLight( _light,rmouse.X,rmouse.Y,lightRot+Pi+Pi/2 )For Local x:=0 Until Width Step _floor.WidthFor Local y:=0 Until Height Step _floor.Heightcanvas.DrawImage( _floor,x,y )NextNextFor Local an:=0.0 Until TwoPi Step TwoPi/8.0canvas.DrawImage( _logo,Width/2+Cos( an ) * Width/4,Height/2 + Sin( an ) * Height/4 )Nextcanvas.EndLighting()canvas.DrawText( Floor( App.FPS+.5 ),Width/2,0,.5,0 )EndEndOr is it all rendering after RequestRender()
Sorry but we need more tutorialsJuly 17, 2018 at 1:49 am #15066As I understand it; rendering happens automatically after OnRender, which means it always happens after you’ve drawn all your stuff.
App.RequestRender() only tells the application that you want another frame to be rendered as soon as possible, and since you’ll want that to happen continuously in a game App.RequestRender() is called in the OnRender method itself.
So it won’t matter where or when you call App.RequestRender() really, rendering still occurs after OnRender.If you were making an app instead of a game — which only needs to render when things change e.g.; you press a button, move a slider etc. — you could use App.RequestRender() specifically when a button event happens for example.
July 17, 2018 at 8:10 am #15067It doesn’t change anything if App.RequestRender() is at the beggining or at the end of OnRender(). It just means that OnRender must be called the next time.
But you can set SwapInterval=0 so there is no Vsync, it will redraw as fast as it can.To control the framerate (for screen with a vsync different from 60fps e.g.) you can use a timer and SwapInterval=0, calling App.RequestRender() thru the timer.
See spacechimps banana for an example. It uses a lot of OnBlah stuff but is readable.
July 17, 2018 at 8:48 am #15068okay but all code that comes after App.RequestRender() would be render on the next App.RequestRender().
Is SwapInterval = 1 set by default?Btw. what timer commands can i use? (sorry but the language reference freezes often my Firefox)
July 17, 2018 at 4:55 pm #15071but all code that comes after App.RequestRender() would be render on the next App.RequestRender().
No, in current frame. There could be another Game template that hides such kind of stuff..
what timer commands can i use?
Timer for 50fps:
New Timer( 50,Lambda()
‘ your code here
End )
July 17, 2018 at 5:07 pm #15072I found timer
i forget that the online help is not state of builds.
And timer is going another way like i thought…but very useful.App.RequestRender: in short all code in the onupdate methode was rendered with the call of App.RequestRender.Right?
Independend where RequestRender stays in the code.
July 18, 2018 at 5:13 pm #15076What is onupdate in your case?
You can have timer with 120fps rate but call render each second ‘frame’, for example.
In timer func:
If counter mod 2=1 App.RequestRender()
counter+=1
In that case you have twice more updates than renders.
July 18, 2018 at 7:59 pm #15078I thought in another direction.
I thought all what is inside onrender object was send automatic to the rendertarget.Now i´m a little bit confused.
I thought in onupdate i handle some things i.e. keyboard input and so on.
And then in onrender all inside that object was send to the render target via RequestRender.onrender and onupdate are only a shell.
Theoretical i can do that all in onupdate or onrender?
Or are there differences between these both classes?edit: i see “override” so i have to look inside these both classes.
edit2: after a few hours of reading the reference maze
i understand the internal of M2 a little bit more.
onrender is a view methode.onupdate was a user created class for better code reading and handling.July 19, 2018 at 8:27 am #15084yes onupdate was user created and could have another name.
Drawings are always made in Onrender because it’s the only place where you receive the canvas.
July 23, 2018 at 4:02 pm #15123I thought all what is inside onrender object was send automatic to the rendertarget.
Now i´m a little bit confused.
RequestRender – it’s just Request, not actually *Do*Render.
So you just ask app to call window.OnRender (all windows if there few) when next step of game loop occured.
I thought in onupdate i handle some things i.e. keyboard input and so on.
And then in onrender all inside that object was send to the render target via RequestRender.There is no OnUpdate but it’s easy to split OnRender to Update and Render
Monkey12345678910111213141516Method OnRender( canvas:Canvas ) OverrideUpdate()Render( canvas )RequestRender() ' ask app to render next frame to have infinite rendering (each step of game loop)EndPrivate ' or protected or publicMethod Update()' perform all updatesEndMethod Render( canvas:Canvas )' perform all rendering operations hereEndJuly 23, 2018 at 4:17 pm #15124@hezkore ah okay thank you i was wondering how it worked as well
did you not read hezkores reply? it answers most questions
July 23, 2018 at 8:47 pm #15126I wrote “i thought”. I understand it now.
-
AuthorPosts
You must be logged in to reply to this topic.