nunziox Posted May 7, 2014 Share Posted May 7, 2014 I need of painting into a canvas while the game is run.I'd want to set the physic at the painted element.is it possible? Link to comment Share on other sites More sharing options...
jpdev Posted May 7, 2014 Share Posted May 7, 2014 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 More sharing options...
Recommended Posts