Jump to content

Draw Solid Rectangle


owenconti
 Share

Recommended Posts

I'm very new to Phaser, so please bare with me.

 

Is this the easiest way to create a solid-colored rectangle?

this.completionSprite = game.add.graphics( 0, 0 );this.completionSprite.beginFill(0xFFFF00, 1);this.completionSprite.bounds = new PIXI.Rectangle(0, 0, 200, 200);this.completionSprite.drawRect(0, 0, 200, 200);

I originally tried that without the 3rd line, but my Rectangle ended up being greater than 200x200 (around 220px, as if there was 10px padding on it)

 

Am I doing something wrong? Why do I have to set the x/y/width/height twice?

Link to comment
Share on other sites

 

Is this the easiest way to create a solid-colored rectangle?

 

1.) Draw

var drawnObject;
var width = 100 // example;
var height = 100 // example;
var bmd = game.add.bitmapData(width, height);
 
bmd.ctx.beginPath();
bmd.ctx.rect(0, 0, width, height);
bmd.ctx.fillStyle = '#ffffff';
bmd.ctx.fill();
drawnObject = game.add.sprite(game.world.centerX, game.world.centerY, bmd);
drawnObject.anchor.setTo(0.5, 0.5);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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