About rendering


(Elias) #1

Can anyone explain what render basicaly is? Whats the render function of flashpunk is used for?


(Jacob Albano) #2

“Rendering” is a really abstract term, but in the context of game development it usually refers to displaying graphics on the screen. When Flashpunk renders, it calls render() on the active World, which in turn calls render() on every visible Entity, which in turn calls render() on its graphic (which, if it’s a Graphiclist, calls render() on each graphic contained within it). :stuck_out_tongue:


(Ultima2876) #3

Further to this, it isn’t something you generally need to worry about unless you want to do some advanced effects when an Entity renders itself. For example, to make a water distortion effect you could use an Entity’s render() function to read the current screen buffer into a BitmapData, apply a ripple effect to it (And perhaps tint it slightly if you prefer tinted water) then draw that to the screen.


(Elias) #4

Thanks for the quick reply guys. I kinda understand what rendering in technology is, but when it comes to FP is something new to me. When i tried to use the draw function, i could only draw stuff onscreen only by using the render function. So if there are a thing or two that i must know about it, it would very kind of you if you could give me some info. What is the screen buffer anyway? Thanks again! :smile:


(Jacob Albano) #5

Before rendering, the screen is cleared. If you use the Draw class during update(), it will be overwritten before the world is rendered.


(Ultima2876) #6

When making games we commonly use a method called ‘double buffering’ - FlashPunk is the same. Basically there are two ‘buffers’ (bitmaps); the backbuffer and the frontbuffer. The backbuffer is what we draw to and is actually invisible while drawing to it. The frontbuffer is what is shown on screen.

FlashPunk does something like this:

  1. update all objects
  2. clear back buffer
  3. render all objects to back buffer (call render functions)
  4. flip buffers (front buffer becomes back buffer, back buffer is shown on screen)

As you can see, if you draw anything to the back buffer (FP.buffer, using Draw etc) before it is cleared… it won’t show, because by the time the buffer is shown on screen it will have been cleared!

You might ask why it is cleared after updating all the objects and not before (thus allowing you to draw stuff in your update() functions)… I’ll leave that as something for you to think about. :wink: A hint is that I’ve discussed it on these forums before, and it’s to do with good game coding practices.


(Elias) #7

Thanks again, it helped a lot!


(Ultima2876) #8

No worries. Any time :slight_smile: