Jump to content

Live Text Update Question


UseTheForceFrodo
 Share

Recommended Posts

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

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...