Jump to content

does Phaser use a spatial structure to discard out-of-screen objects ?


Recommended Posts

I must develop a game with a very large level, with about 500 objects inside.

How will Phaser manage the stuff ?

- does Phaser perform a stupid brute-force test on my 500 objects to check if they're out of screen, and so kill players' CPU ?

- does Phaser stores cleverly my 500 objects in a spatial structure (like grid,quadtree...) to make a fast search on local objects ?

Thanks to help me.

Link to comment
Share on other sites

No, those offscreen objects will still use CPU. There's no way to stop that, though. If they didn't use CPU to update themselves you wouldn't know when they were coming onscreen from offscreen.

For most games, rendering is the most expensive operation vs. any game logic you do. And I'm pretty sure that Phaser's rendering engine makes use of WebGL such that the graphics card will not waste time rendering anything offscreen. Offscreen culling is way faster in the GPU than in the CPU, anyway. Spatial hashes are much more of a physics engine thing than a graphics engine thing, I think.

Try testing your game and see how much CPU it uses with offscreen objects, see if it's acceptable.

Link to comment
Share on other sites

  • 2 weeks later...

Thanks for informations.

I made my last game without phaser, developed from scratch, it uses the old-school method of object pool generators in a large tilemap, so offscreen objects just doesn't exist. So i think i should keep this method for games with very large maps.

Do you know a javascript game library working that way ?

Link to comment
Share on other sites

38 minutes ago, stopviolence said:

I made my last game without phaser, developed from scratch...

Did the last game you created leverage GPU acceleration to maximize rendering? You get that out-of-the-box with Phaser. I think Phaser's implementation exploits (OpenGL) clipping options so that objects are not rendered off-screen, so unless those objects are used in a context independent of rendering (like physics for example) you don't have to worry about object pooling. All the rendering stuff is handled internally (and efficiently) by the GPU.

I'd suggest you take drhayes advice and test it for yourself. You can try one of the bunny mark tests or create your own. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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