owenconti Posted July 5, 2014 Share Posted July 5, 2014 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 More sharing options...
titmael Posted July 5, 2014 Share Posted July 5, 2014 http://examples.phaser.io/_site/view_full.html?d=display&f=graphics.js&t=graphics is it what you want ?What do you mean solid ? With physics ? Link to comment Share on other sites More sharing options...
lukaMis Posted July 5, 2014 Share Posted July 5, 2014 Is this the easiest way to create a solid-colored rectangle? 1.) Drawvar 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); Lypzis 1 Link to comment Share on other sites More sharing options...
lewster32 Posted July 5, 2014 Share Posted July 5, 2014 All Graphics objects by default have a 10 pixel padding. To fix this just do:this.completionSprite.boundsPadding = 0; Jimaginary, MichaelD and globalkeith 3 Link to comment Share on other sites More sharing options...
Recommended Posts