Jump to content

BitmapText inside BitmapData error


Yora
 Share

Recommended Posts

Hi,

 

I'm trying to have some static BitmapText objects made into a texture to help performance via a BitmapData object.  This method works when using a Phaser.Text object, but not with BitmapText which generates the error below.  I can't seem to figure out how to fix this problem, thanks in advance for any help.  :)

var text = this.game.make.bitmapText(0, 0, 'AFont', 'text', 54);            var bmd = this.game.add.bitmapData(256, 256);            bmd = bmd.draw(text);            var test = this.game.add.sprite(100, 0, bmd);
TypeError: Cannot read property 'size' of undefined    at b.BitmapText.updateText (http://localhost/phaser/dist/js/phaser.min.js:3:23264)    at b.BitmapText [as constructor] (http://localhost/phaser/dist/js/phaser.min.js:3:22630)    at new c.BitmapText (http://localhost/phaser/dist/js/phaser.min.js:13:21942)    at c.GameObjectCreator.bitmapText (http://localhost/phaser/dist/js/phaser.min.js:12:15772)    at Object.BattleState.INIT_UI (http://localhost/phaser/dist/js/game.js:1684:39)    at Object.BattleState.create (http://localhost/phaser/dist/js/game.js:1222:14)    at c.StateManager.loadComplete (http://localhost/phaser/dist/js/phaser.min.js:7:31019)    at c.Loader.finishedLoading (http://localhost/phaser/dist/js/phaser.min.js:16:21149)    at c.Loader.processLoadQueue (http://localhost/phaser/dist/js/phaser.min.js:16:20720)    at c.Loader.asyncComplete (http://localhost/phaser/dist/js/phaser.min.js:16:21333)
Link to comment
Share on other sites

Thanks for the reply Rich. :)   Indeed, I had read something when searching about it that made me think it could be done in some way, but I may have just misunderstood.  

 

While using CocoonJS in Canvas, having a large number of BitmapText objects seems to take a on hit my performance, even moreso than large numbers of complex animations.  There are still many optimizations I can make in my code, though it would definitely be ideal to have these 52+ BitmapTexts converted into 4 texures used in 4 sprites.  

Link to comment
Share on other sites

Yeah BTs are super heavy because each letter is its own Sprite. You can cache each one as an image, but even that's a bit heavy if you've got lots of them (especially if they need to update).

 

BitmapData has a 'drawGroup' method - it's really simple, you could probably recreate it yourself locally and pass it a BitmapText instead.

Link to comment
Share on other sites

Thanks for pointing me in the right direction, I made this change to drawGroup and while it's not too pretty I was able to get exactly what I wanted to work from it.   :wub:

// OriginaldrawGroup: function (group, blendMode, roundPx) {        if (group.total > 0)        {            group.forEachExists(this.copy, this, null, null, null, null, null, null, null, null, null, null, null, null, null, null, blendMode, roundPx);        }        return this;    },
// New        drawGroup: function (group, blendMode, roundPx) {        for(var i = 0; i < group.children.length; i++) {            for(var e = 0; e < group.children[i].children.length; e++) {                this.copy(group.children[i].children[e], 0, 0, null, null, group.children[i].x + group.children[i].children[e].x, group.children[i].y + group.children[i].children[e].y);            }        }        return this;    },
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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