michael
michael

Reputation: 4483

Loading spritesheet from bitmapdata in Phaser

I'm trying to build up an image using BitmapData and use that image as a spritesheet but I think I'm missing something.

I'm doing this in my preload...

oBitmapData = game.add.bitmapData(tileWidth * 2, tileHeight);
oBitmapData.ctx.fillStyle = 'blue';
oBitmapData.ctx.fillRect(0,0,tileWidth, tileHeight);
oBitmapData.ctx.fillStyle = 'red';
oBitmapData.ctx.fillRect(tileWidth,0,tileWidth, tileHeight);

oSpriteSheet = game.load.spritesheet(tiles[key].name + 'Sheet', oBitmapData, tileWidth, tileHeight);

And then this elsewhere...

game.add.sprite(x, y, tiles[key].name + 'Sheet', 0, tilesGroup);

I get the following error when running the code

Uncaught TypeError: url.match is not a function

Could someone steer me in the right direction please?

Upvotes: 0

Views: 481

Answers (2)

ivanixdev
ivanixdev

Reputation: 371

To add a bitmapdata as a spritesheet to phaser:

game.cache.addSpriteSheet('key',null,bitmapdata.canvas, framewidth, frameheight);

Upvotes: 1

BdR
BdR

Reputation: 3048

The spritesheet() function can only take a url image not a bitmapData object, see documentation, that is causing your error.

And creating a sprite sheet from bitmapdata is not supported by the framework AFAIK, at least according to this forum thread.

Upvotes: 0

Related Questions