Jump to content

How to draw bitmapText on the bitmapData?


San4er
 Share

Recommended Posts

I can't make it, help please  :( I'm using Phaser 2.1.1.

 

var bmd=game.make.bitmapData(100,100);bmd.draw('background',0,0);var sLeaf=game.make.image(0,0,'leaf2');bmd.draw(sLeaf,0,0);//works finevar sText=game.make.bitmapText(0,0,'myFont','blah blah',30);bmd.draw(sText,0,0);//doesn't workbmd.update();game.add.image(0,0,bmd);

I get an error "Argument 1 of CanvasRenderingContext2D.drawImage could not be converted to any of: HTMLImageElement, HTMLCanvasElement, HTMLVideoElement. phaser.js:31756" when I try this.
I also tried bmd.load, bmd.copy and bmd.copyRect. Nothing works.
It seems like bitmapData.load supports all kind of sources(Phaser.Sprite| Phaser.Image| Phaser.Text | Phaser.BitmapData | HTMLImage |HTMLCanvasElement | string) but not a BitmapText:

http://docs.phaser.io/Phaser.BitmapData.html#load

Is there any solution to draw bitmapText on the bitmapData?

Link to comment
Share on other sites

  • 1 month later...

The thread might be a little old, but was the only thing that popped up when I googled the problem. This is how it worked for me.

var bitmapData = new Phaser.BitmapData(game, null, 1920, 1080);var bitmapText = new Phaser.BitmapText(game, 0, 0, 'font', 'Hello BitmapData', 48);bitmapText.updateText();// Build a canvas-backed Sprite/RenderTexture for the BitmapData and cache itvar canvasRenderer = new PIXI.CanvasRenderer(bitmapText.width, bitmapText.height);var renderTexture = new PIXI.RenderTexture(bitmapText.width, bitmapText.height, canvasRenderer);bitmapText._cachedSprite = new Phaser.Sprite(game, 0, 0, renderTexture);bitmapText._cachedSprite.worldTransform = bitmapText.worldTransform;bitmapText.cacheAsBitmap = true;// Draw the cached SpritebitmapData.draw(bitmapText._cachedSprite, x, y);
Link to comment
Share on other sites

  • 4 months later...
 Share

  • Recently Browsing   0 members

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