Sign in to follow this  
owenconti

Draw Solid Rectangle

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?

Share this post


Link to post
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);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.