UseTheForceFrodo Posted April 9, 2015 Share Posted April 9, 2015 I'm aiming towards having a small text panel on the left hand side of the screen which contains data pertaining to my sprites (position etc). I wouldn't know how to set live updating text in Phaser though.I made this little sandbox to help explain:http://phaser.io/sandbox/HztzhGmk Where I have the text "circle position" is where I would like live updates of the circle's x and y position [ example: game.add.text(10, 32, "x: " + sprite.x, style); ]. The circle is draggable, but I'm not sure how to access and display the positional values for a sprite in real time. Any help much appreciated. Many thanks in advance. Link to comment Share on other sites More sharing options...
grumpygamer Posted April 9, 2015 Share Posted April 9, 2015 What I'd do is get the new coordinates via the object properties and then use text.setText(x+' '+y); Link to comment Share on other sites More sharing options...
BattyMilk Posted April 9, 2015 Share Posted April 9, 2015 Change your create function to:function create() { var bmd = game.add.bitmapData(300, 300); bmd.circle(150, 150, 64, 'rgb(0,200,0)'); sprite = game.add.sprite(200, 0, bmd); sprite.inputEnabled = true; sprite.input.enableDrag(); var style = { font: "16px Garamond", fill: "#ffffff", align: "left" }; text = game.add.text(10, 32, "circle postion", style);} And your update function: function update() { text.text = "x:" + sprite.x + " y:" + sprite.y;} (I couldn't work out how to fork your sandbox or share my changes to yours) Link to comment Share on other sites More sharing options...
drhayes Posted April 9, 2015 Share Posted April 9, 2015 You should check out the Debug class. It has lots of useful ways of printing this info for you. Link to comment Share on other sites More sharing options...
UseTheForceFrodo Posted April 10, 2015 Author Share Posted April 10, 2015 Thanks for the replies guys - super helpful. I have achieved what I was after in my original post. Thank's BattyMilk for the code. I ended up going with text.setText = ... instead of text.text = ... drhayes, I discovered the debug class already when looking into lines. Lots of wonderful debug info already available. Ultimately I'll need to be creating my own methods though, hence this topic. Thanks for the help everyone. Link to comment Share on other sites More sharing options...
Recommended Posts