Change text colour dynamically

Recommended Posts

Hi all,


Is this possible? e.g. 

// Create textvar t =, 10, "Hello World", { font: "16pt Arial", fill: "#FFFFFF", align: "center" });// Ideally not this because it uses internal values, and actually doesn't update the text displayed. t._style['fill'] = "#FF0000";// Perhaps something like this...!t.updateCSS({ font: "16pt Arial", fill: "#FF0000", align: "center" });


Share this post

Link to post
Share on other sites

setStyle() is inherited from PIXI.Font, so it is found in the PIXI docs, not the Phaser docs.
What you find in the Phaser docs is the Text.font property:

/*** The font the text will be rendered in.* @name Phaser.Text#font* @property {string} font - The font the text will be rendered in.*/Object.defineProperty(Phaser.Text.prototype, 'font', {    get: function() {        return this._style;    },    set: function(value) {        //  Let's not update unless needed, this way we can safely update the text in a core loop without constant re-draws        if (value !== this._style)        {            this._style = value;            this.setStyle(value);        }    }});

Share this post

Link to post
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.