Jump to content

Does Phaser need to requestAnimationFrame() if there are no animations?


Sanic
 Share

Recommended Posts

I've been stress testing my browser to see how much I need to worry about optimizing my game in the future. When I load up a large Tilemap and zoom out (to jam as much of the map on the screen as possible before it crashes) chrome dev tools tells me most of the time spent per frame (and this is at 4 frames per second) is used up by numerous expensive calls to requestAnimationFrame() and hardly any time rendering in comparison.

I'm just wondering if this is critical to call for tiles that don't animate? It doesn't seem so but I'm not sure if it's hooked into anything else that's critical.

Link to comment
Share on other sites

Think of raf as being the beating heart of Phaser. Every time it beats, it updates all of the internal systems, renders the scene and prepares itself for the next heart beat. Disable the heart, and you disable the entire game from updating, not just the animations. The cost is most likely just the rendering of the tilemaps (rather than raf itself), which are really slow under WebGL I'm afraid.

Link to comment
Share on other sites

Chrome dev tools shows you if it's the render time that's taking forever. (This is just of what I'm working on now which is a graphics texture a small blank tilemap and some text, but the amount of 'rendering' wasn't much more than the amount of 'painting' seen below and the 'painting' wasn't any larger either.)

scripting.PNGscripting2.PNG

Render time, at least on my machine, isn't a limiting factor is what I'm saying.

So RAF is what keeps the game ticking over? I won't mess with it then, lol.

But how are tilemaps being prepared per tick for WebGL? I've worked with OpenGL before and I know I've I've run into performance problems trying to send things like the entire buffer of tilemap vertices to the graphics card every frame... it wasn't immediately obvious why I shouldn't do that. And JS doesn't exactly give you tight control over how to store your data so that'd make it really hard to work with WebGL.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...