staff0rd Posted May 12, 2016 Share Posted May 12, 2016 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; Quote 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(); group.add(sprite); 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 More sharing options...
rich Posted May 12, 2016 Share Posted May 12, 2016 (edited) BitmapData.draw can't draw PIXI.RenderTexture objects (it's not part of the method signature, or in the docs), which is what generateTexture returns. Edited May 12, 2016 by rich Changed Texture to RenderTexture (same end result though) Link to comment Share on other sites More sharing options...
staff0rd Posted May 12, 2016 Author Share Posted May 12, 2016 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); bmd.draw(sprite2); Link to comment Share on other sites More sharing options...
staff0rd Posted May 12, 2016 Author Share Posted May 12, 2016 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 More sharing options...
rich Posted May 12, 2016 Share Posted May 12, 2016 Just edited my message to clarify that it can't draw RenderTextures, which is what Sprite.generateTexture returns. Same end result though. Edit: Fine, fine, here you go: https://github.com/photonstorm/phaser/commit/f34b56729598553cc21d3693db95c88bb41c6c94 drhayes 1 Link to comment Share on other sites More sharing options...
staff0rd Posted May 12, 2016 Author Share Posted May 12, 2016 You're a boss! I'm using typescript and generateTexture() returns a PIXI.Texture, so I've opened a PR to have it return RenderTexture. Fix for the original post is; var texture1 = sprite.generateTexture().getCanvas(); bmd.draw(texture1); // works! Link to comment Share on other sites More sharing options...
Recommended Posts