SYNYST3R1 Posted October 17, 2013 Share Posted October 17, 2013 I am drawing a rectangle around the tile my mouse is over, but it draws a new rectangle every time I go over a new tile. How could I make it update the position of the rectangle instead of drawing a new rectangle every time?if(msX >= tileX * tileWidth && msX <= (tileX + 1) * tileWidth && msY >= tileY * tileHeight && msY <= (tileY + 1) * tileHeight) { var g = game.add.graphics(0, 0); g.lineStyle(2, 0x000000, 1); g.drawRect(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight); } Link to comment Share on other sites More sharing options...
rich Posted October 17, 2013 Share Posted October 17, 2013 Just draw the rectangle once, at the size you need it (your tileWidth, tileHeight values) and then position the graphics object where the mouse is. If you're using the current dev branch you can just do:g.x = game.input.x;g.y = game.input.y;Have a look at the examples/tilemaps/paint tile demo for a good example of doing just this. If you're on the current master branch then I'm pretty sure you can still do it, but just use:g.position.xinstead. Link to comment Share on other sites More sharing options...
SYNYST3R1 Posted October 17, 2013 Author Share Posted October 17, 2013 I'm on the latest dev branch. I put g.y in the console log and the position is definitely updating, but the rectangle isn't moving.var g;function create() { g = game.add.graphics(); g.lineStyle(2, 0x000000, 1); g.drawRect(0, 0, tileWidth, tileHeight);}function update() { g.x = tileX*tileWidth; g.y = tileY*tileHeight; console.log(g.y);}That's basically the short version of what I have Link to comment Share on other sites More sharing options...
rich Posted October 17, 2013 Share Posted October 17, 2013 When did you last update? That ability was only put in a few hours ago Link to comment Share on other sites More sharing options...
SYNYST3R1 Posted October 17, 2013 Author Share Posted October 17, 2013 I have the latest because I got it after your suggestion of g.x. I need to use the phaser in src correct? I have only ever used the single file phaser.js so idk how to use the one in src and this framework is my first time using html5 / javascript Link to comment Share on other sites More sharing options...
rich Posted October 17, 2013 Share Posted October 17, 2013 Update, I've just pushed up a new single file phaser.js file for you. Link to comment Share on other sites More sharing options...
SYNYST3R1 Posted October 17, 2013 Author Share Posted October 17, 2013 Awesome, thanks! And it works perfect now. Link to comment Share on other sites More sharing options...
bolatro Posted March 24, 2014 Share Posted March 24, 2014 Does it work for version 2.0.0 ? Link to comment Share on other sites More sharing options...
Larzan Posted September 4, 2014 Share Posted September 4, 2014 Yes it does, using it with 2.0.7 right now. Remember that the Phaser.Graphics class is a wrapper for the PIXI.Graphics class and as such inherits (all?) of its methods, so you can also hide it with the Graphics.visible parameter for example... Link to comment Share on other sites More sharing options...
Recommended Posts