Zekko

Camera gets stuck on window resize

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

Share this post


Link to post
Share on other sites

I had a similar problem using Phaser.ScaleManager.RESIZE when i was resizing the world with game.world.resize(width, height).

Resizing the world with game.world.setBounds(x, y, width, height) fixed it for me.

Share this post


Link to post
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? ;)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.