Sign in to follow this  
zoltan88

Camera gets stuck on resize event with scaleMode RESIZE

Recommended Posts

So I'm currently using Phaser 2.9.1 and had a weird issue I've been struggling with today.

If I use scaleMode RESIZE, then whenever the window resizes, the camera gets stuck at 0,0 and wont move anymore. Debugging reveals that the update function is called and the camera x,y are changed whenever the buttons to move the camera are pressed. However, it's like they are changed back right away again. One theory I had was that the world gets resized to the browser innerWidth and innerHeight upon resizing with that scaleMode.

 

I found a thread after a while that fixed my problem. The problem now is that I want to know why it works....

 

So, doing the following in my create function:

game.world.resize(5000, 5000);
game.world.setBounds(0, 0, 5000, 5000);

works, for some reason. Only doing resize does not work and I have to use setBounds there. But according to the docs, resize sets the size of the world and setBounds sets the camera to 0,0 and then sets the size of the world. Why would that make a difference when the browser is resized after the game has been created and the update function is running? 

If anyone could shed some light on this, I would greatly appreciate it :-).

Also creds to Zekko and Carlos in the post above, for solving the issue 2 years ago :P

Share this post


Link to post
Share on other sites

I guess the docs are slightly incomplete. The difference is that world.setBounds actually sets a minimum size and world.resize never resizes below the minimum. word.resize is actually what gets called following a window resize; I don't think it's supposed to be a substitute for setBounds.

Share this post


Link to post
Share on other sites
2 hours ago, samme said:

I guess the docs are slightly incomplete. The difference is that world.setBounds actually sets a minimum size and world.resize never resizes below the minimum. word.resize is actually what gets called following a window resize; I don't think it's supposed to be a substitute for setBounds.

Alright, thank you! : )

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.