Jump to content

How to change the color of a rectangle


Recommended Posts

Hello there,


I'm just starting with Phaser, so sorry about this very basic question. I can't seem to successfully update the color of a Rectangle. Here is my code so far:


// drawing player
this.player1 = new Player(0, 20, "0xFFFF33");
this.player1.graphic = this.game.add.graphics(this.player1.size,this.floor.base-this.player1.size); 
this.player1.graphic.beginFill(this.player1.color, 1);
this.player1.graphic.drawRect(0, 0, this.player1.size, this.player1.size);


update: function() {
    this.player1.graphic.graphicsData[0].fillColor = this.player1.breakdown ? '0XFF0000' : '0XFFFF33';
The following do update the color, but I need it to change only when certain conditions are met:
update: function() {
    this.player1.graphic.graphicsData[0].fillColor = '0XFFFF33';
There is probably a method I can call to update the color, but looking at Phaser/Pixi docs I can't seem to find anything.
Thanks for your help!  :)
Link to comment
Share on other sites


  • Recently Browsing   0 members

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