I use culling on my Tiles in my 2D Platformer (XNA), so only ones needed are drawn on screen. Thats easy to do.

However, My Liquid tiles (Water, lava, etc) require an Update Method aswell as the normal Draw, which does checks against tiles, makes it flow, etc.

So how should I cull liquid updates in my game? Not culling is to slow, culling only on screen looks awkward when you move.

What do you think would be best for the player? Maybe someway of culling the visible tiles PLUS also adding the width/height of the viewport to start culling tiles at a fast enough rate in front of the player so it dosent look awkward when moving? (Not sure how to do this though, something with MaxSpeed of player and width of screen)


1 Answer 1


Generally, you should not “cull” physics updates in your game with respect to the screen, except perhaps to a very limited extent — things not moving when they are off-screen is now seen as archaic. What you need to do instead is make the updates more efficient.

You state that you have tile-based liquids. I assume they are flowing around by checking their neighbor tiles and converting those into liquid tiles, or other similar local rules. Here is a technique for optimizing such updates which saves time when most of your liquids are stationary, but the environment will sometimes change to allow it to flow.

  • Have a set/list of “currently moving liquids” — this is a list of tile positions.

  • Whenever any tile changes its state in a way that might affect liquids, check if it or its neighbors are liquid; for any tile that is, put it on the list of moving liquids.

  • When you update the level,

    1. Save the current “moving liquids” list aside, and clear the original list.

    2. For each tile in the saved list, perform its update. If the liquid flows, then that update will of course cause one or more tiles to be added to the just-cleared list for further processing next frame.

That's it! In this way, no CPU time is spent on liquid that is not moving.

(If you have levels where the liquid starts flowing as soon as it is loaded, then you need only make sure it gets onto the list; you can do this either by putting every liquid tile on the list as the level is loaded, or by having a premade list of initially-flowing-water tiles.)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .