dnassler Posted April 2, 2014 Share Posted April 2, 2014 Hi, I'd like to programmatically create a sprite animation rather than have to create a spritesheet and load it. Is there a way of doing that? Basically I want to be able to create a bitmap data object and draw to it then have it treated as a set of frames that I could use to play animations from. Link to comment Share on other sites More sharing options...
rich Posted April 2, 2014 Share Posted April 2, 2014 There's no support for this presently (not without a lot of hacking around anyway, it's possible, but not "out of the box") Link to comment Share on other sites More sharing options...
dnassler Posted April 2, 2014 Author Share Posted April 2, 2014 I just found a way! Thought I would share... With help from another post related to dynamic image creation I was successful by doing the following: in the game loader I created a bitmapData object and drew to it using the bitmap context drawing methods then got the bitmap data's canvas and from that did a toDataURL... then did a game.load.spritesheet with the dataURL as if it was an image file.var dataURL, bmd, ctx, width, height;width = 100;height = 100;bmd = game.add.bitmapData( width * 2, height );ctx = bmd.context;bmd.clear();ctx.fillStyle = "#2E8B57";ctx.fillRect(0,0,width,height);ctx.fillStyle = "#FFFFFF";ctx.fillRect(0,0,width/2,height/2);ctx.fillRect(width/2,height/2,width/2,height/2);ctx.fillStyle = "#2E8B57";ctx.fillRect(width,0,width,height);ctx.fillStyle = "#FFFFFF";ctx.fillRect(width+width/2,0,width/2,height/2);ctx.fillRect(width,height/2,width/2,height/2);dataURL = bmd.canvas.toDataURL();game.load.spritesheet('myDynamicSpritesheet', dataURL, width, height);The above creates a spritesheet of 2 frames dynamically... of a box composed of smaller green and white boxes. Arcanorum and Dower 2 Link to comment Share on other sites More sharing options...
rich Posted April 2, 2014 Share Posted April 2, 2014 Very nice I would imagine you could skip the game.load.spritesheet part though and just add it directly into the Cache? Link to comment Share on other sites More sharing options...
Recommended Posts