Jump to content

How to add a gradient color


greendot
 Share

Recommended Posts

Hi ,

You can use the following to create gradient in Phaser 3. 


     var canvasTexture = this.textures.createCanvas('buttonTexture', 300, 60);
     var src = canvasTexture.getSourceImage();
     var context = src.getContext('2d');
     var gradient = context.createLinearGradient(0,0,0,60);
     gradient.addColorStop(0,"#ffffff");
     gradient.addColorStop(1,"#000000");
     context.fillStyle = gradient;
     context.fillRect(0,0,300,60);

//Below is required only when running the game in WEBGL
     canvasTexture.refresh();
     
     this.add.image(10,100,"buttonTexture");

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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