Create spritesheet from sprite (or bitmapdata)

I am trying to dynamically create spritesheets on the fly in order to change the appearance of my characters (hair, clothes, etc). To do this I am adding multiple sheets in layers to a group, and then creating the sprite using the cached sprite texture from the group (bitmap, which I can convert to sprite) and so far that part is working great.

The trouble is, I’m having difficulty figuring out how to convert either bitmapdata or a sprite into a spritesheet. Using game.load.spritesheet only allows the spritesheet to be added as a URL.

Does anyone know of a way to convert either bitmapdata or sprite to a spritesheet?

Any help or thoughts would be greatly appreciated!!

I think I’m about 95% of the way there and wanted to post my solution thus far:

preload(){ //Load the sprite sheets
game.load.image(‘testsheet1’, ‘testsheet1.png’);
game.load.image(‘testsheet2’, ‘testsheet2.png’);
}

//Add spritesheets to group
sheetGroup.create(0, 0, “testsheet1”);
sheetGroup.create(0, 0, “testsheet2”);

//Get the texture from the group
var bmdSprite = sheetGroup._cachedSprite.texture;

//Create bitmapdata from the group
var bmd = game.make.bitmapData();
bmd.load(bmdSprite);

//Add the new spritesheet
game.cache.addSpriteSheet(‘test sheet’, ‘’, bmd.canvas, 128, 256, 12, 0, 0);

This works; the only issue is that the edges of the resulting spritesheet are very pixellated. I created a separate thread for that here: