Jump to content

how to clear the canvas?


Mike018
 Share

Recommended Posts

Without using phaser, I can do something like this.

ctx.clearRect(0, 0, GAME_WIDTH, GAME_HEIGHT); 

 

Currently I just have rectangles and no sprites. I've even tried to convert the rectangles to bitmap and do this:

var bmd = game.add.bitmapData(0,0);    bmd.ctx.clearRect(0, 0, game.world.width, game.world.height);   All within function create()

 

Also, is there a way to just clear the objects that are moving and leave the static images? I'd imagine that would be more performant. 

Link to comment
Share on other sites

You should probably think in terms of Sprites, not canvas context calls: http://phaser.io/examples/v2/category/sprites

If you need to create things dynamically, you can draw to a BitmapData and use that as the texture for a sprite. Phaser will, by default, clear the canvas between renders unless you tell it not to -- but I'd make the game first and save the performance optimizations for later when you're sure you need them. "Sure you need them" as in "measured with a profiler and determined exactly where the problem is".

Link to comment
Share on other sites

  • 1 year later...

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