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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.