Jump to content

Paint in a game


nunziox
 Share

Recommended Posts

You need to create a bitmap data, draw into that, and then create a sprite from this bitmap data.

On this sprite you can enable physics and do everything with it, that you can do with "normal" sprites.

 

For example like this:

var myBitmap = game.add.bitmapData(800, 600);var grd=myBitmap.context.createLinearGradient(0,0,0,500);grd.addColorStop(0,"white");grd.addColorStop(1,"#0a68b0");myBitmap.context.fillStyle=grd;myBitmap.context.fillRect(0,0,800,580);grd=myBitmap.context.createLinearGradient(0,580,0,600);grd.addColorStop(0,"#0a68b0");grd.addColorStop(1,"black");myBitmap.context.fillStyle=grd;myBitmap.context.fillRect(0,580,800,20);game.add.sprite(0, 0, myBitmap);

This creates a sprite (800 by 600 pixel) from a bitmap data that contains two gradiants.

You can use any and all canvas draw functions to manipulate the bitmap data.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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