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

It's more a matter of what are you really trying to do.

  • Do you want to restart the game/scene?
  • Do you want to remove all the existing game objects?
  • Do you want to hide (but keep) all the existing game objects?
  • Do you want to flash all black for a moment?
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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