Jump to content

How to render a rectangle with color?


dchhetri
 Share

Recommended Posts

Sounds simple, but from the docs, I can't seem to find a phaser interface todo so, without having to use game.debug or manually change the fillStyle for the context. Anyone know how?

I think the only way to do this is to use game.debug:

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: create, render: render });var floor;function create() {    floor = new Phaser.Rectangle(0, 550, 800, 50);}function render () {    game.debug.renderRectangle(floor,'#0fffff');}

Is there a particular reason why you do not want to use game.debug?

Link to comment
Share on other sites

I think the only way to do this is to use game.debug:

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: create, render: render });var floor;function create() {    floor = new Phaser.Rectangle(0, 550, 800, 50);}function render () {    game.debug.renderRectangle(floor,'#0fffff');}

Is there a particular reason why you do not want to use game.debug?

 

 

From the name I assumed it wasn't necessarily meant to be used for production but just for debugging.

Link to comment
Share on other sites

  • 3 years later...

Hey, also starting with Phaser and just came up with the same question. This is the only info I found on the internets that a Rectangle shouldn't be used in production. Maybe this should be noted in the docs? https://photonstorm.github.io/phaser-ce/Phaser.Rectangle.html Like "Note: for production use a Graphics object, as nothing else will work in WebGL".

Link to comment
Share on other sites

  • 1 month later...

Or just use a sprite with whatever color you want as an image texture. That would be the best from a performance point of view. If you create a graphics object, you're creating a whole new webgl call. 

Bitmap data would be even worse on performance than graphics as you're creating a whole new canvas object. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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