# Create spritesheet from sprite (or bitmapdata)

**URL:** <https://phaser.discourse.group/t/create-spritesheet-from-sprite-or-bitmapdata/8305>\
**Category:** Phaser 2 / CE\
**Created:** [December 8, 2020, 2:09pm UTC](https://phaser.discourse.group/t/create-spritesheet-from-sprite-or-bitmapdata/8305 "2020-12-08T14:09:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![goatfinger07](https://avatars.discourse-cdn.com/v4/letter/g/b19c9b/32.png) [@goatfinger07](https://phaser.discourse.group/u/goatfinger07)\
**Post date:** [December 8, 2020, 2:09pm UTC](https://phaser.discourse.group/t/create-spritesheet-from-sprite-or-bitmapdata/8305/1 "2020-12-08T14:09:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![goatfinger07](https://avatars.discourse-cdn.com/v4/letter/g/b19c9b/32.png) [@goatfinger07](https://phaser.discourse.group/u/goatfinger07)\
**Post date:** [December 8, 2020, 5:02pm UTC](https://phaser.discourse.group/t/create-spritesheet-from-sprite-or-bitmapdata/8305/2 "2020-12-08T17:02:35Z")

</div>

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:

> [@Pixelated edges using bitmapdata](https://phaser.discourse.group/t/pixelated-edges-using-bitmapdata/8307):
>
> I’m trying to figure out how to solve the problem of sprites becoming pixelated when being converted to bitmap data. I have a sprite loaded in my game, and placing the sprite results in the following: game.add.sprite(200, 100, sprite); Now if I convert that sprite to bitmap and back, the edges become very pixelated: var bmd = game.make.bitmapData(); bmd.load(sprite); game.add.sprite(200, 100, bmd); I’ve tried .smoothed=false and antialias=false to no avail. Any idea wh…
