Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

How does position work?


Madigan
 Share

Recommended Posts

Hey guys,

 

I feel kind of dumb for this, but I'm having trouble setting my sprite's position. I'm trying to make the game world "loop" over the screen edges (i.e. things that go off the left side of the screen appear on the right).

 

However, Phaser won't let me set the position. Any idea why?

 

When I run this code, I get the sprite's position, and then the new position (so I know the variable is changing). Then, the second time it runs, its like the position hasn't changed:

console.log(player.position.y);player.position.y = game.height;console.log(player.position.y);

 

Outputs something like:

-316320-317320-318320

I'm using 1.0.7, and I have reproduced the problem on both Chrome and FireFox.

 

Link to comment
Share on other sites

Correct, you use the x/y properties to change sprite placement (unless you are giving it motion, in which case you apply that to the sprite.body).

 

Unless you have enabled collideWorldBounds of course, in which case the sprite would be reset back inside the world again if you try and move it out :)

Link to comment
Share on other sites

  • 1 year later...

@rich

 

So if I have an image object balloonImage which is set to tween. While the image is moving, at some random point of time I want to know the position of the image, I should call this: 

 

balloonImage.body.position.x and balloonImage.body.position.y

 

Is it so?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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