Jump to content

Optimizing Canvas 2D render loops for turn-based board games (dirty rectangles vs full canvas redraw)


payamprivate
 Share

Recommended Posts

Hi everyone,

I'm working on a 2D web-based board game (traditional tabletop grid/board mechanics with checker pieces moving across points). Because it's turn-based rather than an action game, 95% of the time the screen is completely static, with bursts of 60 FPS animation only during piece drags, dice rolls, or checker slide animations.

I'm debating between two architectural approaches for the rendering layer on HTML5 Canvas:

  1. A classic continuous requestAnimationFrame loop that clears and redraws all layers (background board wood grain, pieces, UI overlays) every frame, but only when an isAnimating or isInteracting dirty flag is true, otherwise halting RAF until the next input/state event.
  2. A layered canvas approach: one static background canvas for the heavy textured board surface, and an overlay canvas on top that only re-renders moving pieces, using dirty clipping rectangles (ctx.clearRect(x, y, w, h)) during piece movements.

For modern mobile browsers (especially Safari on iOS where canvas memory footprints and battery consumption can be sensitive):

  • Has the layered multi-canvas approach yielded measurable battery / CPU benefits in your experience compared to just a single canvas with conditional RAF?
  • Are dirty rect clearing optimizations still worth the mathematical bookkeeping overhead given how fast modern 2D canvas 2D contexts are on hardware-accelerated mobile devices?

Would appreciate any insights or benchmarks from folks who have built turn-based or grid games for mobile web!

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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