Jump to content

How to access the coordinates of a moving object in phaser ?


sauravtom
 Share

Recommended Posts

Hi guys, I am back with another noobish question.

 

I have created a text object in my game.

this.text1 = this.add.text(63, 50, "Option 1", style);

and added some fancy tween animation to it.

and now in the update function I want to access its position,

console.log(this.text1.x);

But it only returns "63" i.e the initial position that I created it at, and not the dynamic position.

 

How can I make it return the real time position of the text object ?

 

/*======================================================================*/

I basically wanted to check the position of text to make sure whether it was overlapping with my main character.

I went through the docs and I though that maybe I should use the overlap function for this .

So I added the following in the update function.

this.game.physics.overlap(this.bird, this.text1, this.restart_game, null, this);

But sadly that didn't work either.

 

Link to comment
Share on other sites

Hmm that should work, but it depends how you're tweening it. Try looking at this.text1.position.x/y and see if that differs.

 

@rich, I am tweening the text as follows, 

var tweenTimeMS=1000*(width/pipe_velocity); var tweenAutoStart=true; var tweenDelay=0; var tweenRepeat=false; var tween1 = this.add.tween(this.text1).to( {x:0}, tweenTimeMS, Phaser.Easing.Linear.In, tweenAutoStart, tweenDelay, tweenRepeat); 

and upon using this.text1.position.x , I am getting the initial value( 63 ) as before.

Link to comment
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...
 Share

  • Recently Browsing   0 members

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