Jump to content

Camera gets stuck on window resize


Zekko
 Share

Recommended Posts

Hi guys,

I'm having an issue with Phaser.ScaleManager.RESIZE set. As expected, it resizes the game to the size of the window. However, whenever the window is resized, camera.y gets set to 0 and doesn't respond anymore. Even setting camera.y directly in the update function doesn't do anything. Interestingly, camera.x doesn't seem to be affected. Restarting the game state fixes it, but that doesn't solve that fact that I'm now unable to move the camera after resizing the window.

A similar issue seems to be reported in this post, but there was never a reply.

Does anyone have any ideas what could be the problem? Any and all help will be much appreciated!

 

Cheers,

 

Zekko

Link to comment
Share on other sites

Ah, calling world.setBounds(x, y, width, height) after calling world.resize(width, height) makes it work properly! Thank you!

 

Strangely, calling world.setBounds() by itself makes the camera start at y=0 (and stay stuck there). According to the Phaser docs, world.setBounds() updates both the position and size of the world as well as the camera bounds. I'm having a hard time understanding why I need to call both functions to make the camera do what I want it to do (I also needed to write my own camera bounding function, since the bounds I set don't seem to be respected anymore), but that's probably just me being stupid. Oh well, if it ain't broken don't fix it, right? ;)

Link to comment
Share on other sites

  • 2 years later...
On 6/2/2015 at 12:46 PM, Zekko said:

However, whenever the window is resized, camera.y gets set to 0 and doesn't respond anymore.

Likely the camera gets trapped because its bounds are identical to the world bounds. You can check with debug.cameraInfo().

If you're using scale mode RESIZE, you need to use world.setBounds (not world.resize) if you want to establish the minimum world bounds. Otherwise they'll shrink with the window size.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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