Jump to content

Player spawning at a different position


bandrei2408
 Share

Recommended Posts

Hello,

I have a game which have 4 states : starts with Boot state which then loads Preload state and after Menu State. On the menu state i do something on update function. When the player presses spacebar it loads the Play state. On the Play state i set the body of the player to a rectangle smaller then the actual sprite. Something like this:

this.player = game.add.sprite(700,200,'player');...this.player.body.setRectangle(10,10,20,20);

After that i set the game.camera to follow the player. However, the player spawns everytime at the (0,0) point.

Found two things that would solve my problem, but those solutions are not good since i will delete code that I will actually need. I will post here those two solutions in case it helps you figure out what the problem is. Here they are :

1. Not doing anything on update function in menu state, makes the player spawn at the right position. However, i need to do things on the update function of the Menu state.

2. Removing this.player.body.setRectangle(10,10,20,20) would solve my problem, but i still need to set the player body smaller then the actual sprite for a better collision system.

I would like to mention that i used debug on render to see the body of the player and it is correct.
Any idea what may cause this problem ?
 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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