Jump to content

Camera not positioned correctly after changing start away from scrolling


jzcoder
 Share

Recommended Posts

When we start a new state after the camera has moved over a tilemap world, we can't seem to reset the camera position.

 

I've tried calling this.camera.setPosition(0,0)  and this.camera.view.y = 0, but this does not seem to work.

 

 

Link to comment
Share on other sites

I ran into the same problem, and google send me here.

 

My problem was, a button placed in the menu-state with:

this.btn = this.game.add.button(this.game.world.centerX, this.game.world.centerY, 'startBtn', this.startgame);

Was no longer visible after returning to this state from the game (which uses a tilemap).

 

The solution was to reset the world bounds before creating the button, like this:

    this.game.world.setBounds(0, 0, this.game.width, this.game.height);

Turns out (found out by debugging) that my button was placed at x=24000, y=400 ... because in my gamestate my tilemap-layer is 48000 pixel long, and I call resizeWorld on the layer.

 

Solution: Resize the World to the screen size for the main menu.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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