Jump to content

Is it possible to draw a Texture to a BitmapData?


Recommended Posts

I'm finding that if a texture was created via generateTexture(), or, if a group or sprite contains a texture that was generated by generateTexture(), then calls to BitmapData.copy() fail at this line;

ctx.drawImage(this._image, this._pos.x + x, this._pos.y + y, this._size.x, this._size.y, -newWidth * this._anchor.x, -newHeight * this._anchor.y, newWidth, newHeight);

With the following error;


Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap)'

Some code to reproduce this is as follows;

var sprite = this.game.add.sprite(0, 0, "someimage");
var group = this.game.add.group();

var texture1 = sprite.generateTexture();
var texture2 = group.generateTexture();

var bmd = this.game.add.bitmapData(this.game.width, this.game.height);
bmd.draw(texture1); // fails
bmd.draw(texture2); // fails


Link to comment
Share on other sites

But BitmapData.draw accepts a sprite per the signature/docs, and the following still fails with this;

var sprite = this.game.add.sprite(0, 0, "someimage");
var sprite2 = this.game.add.sprite(100, 100, sprite.generateTexture());
var bmd = this.game.add.bitmapData(this.game.width, this.game.height);



Link to comment
Share on other sites

I note that BitmapData.drawGroup fails in the same manner.

If anyone has any ideas on how I can otherwise solve this i'm keen.  Basically I want to be able to add to the cache an image that was created by combining the output of one or more generateTextures().  Doesn't have to be BitmapData if that doesn't work with textures, but I'm not sure what else there is...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...