bartk

Changing game size dynamically

Recommended Posts

Heya,

 

I'm building a game in which I can enter a building, which I'm handling via states. In other words, when my character overlaps with the door, the program starts a new state in which the interior of the building is built. Now, I want the interior to have smaller dimensions than the world, so I want to change the game size when I start this new state.

I tried this:

create: function(){  //game size was 1000x700, I want to scale it to 700x450  game.width = 700;  game.height = 450;    //rest of creation code...}

I also tried things like changing camera bounds, world bounds, world size, but method above shows the most promise.

The problem, however, is that the resize for some reason does not show until I click away from my browser tab and back. Calling game.width in the console yields 700 at all times, but it doesn't show it as such until tabbing out and back.

 

On top of that, the contents of the game (floor, furniture, character) are scaled down when the game resizes, defeating the purpose. I don't understand why it would, since there's no scaling anywhere in my code.

 

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites

This is how we're doing it in one of our games:

game.width = width;game.height = height;game.stage.width = width;game.stage.height = height;if (game.renderType === Phaser.WEBGL) {    game.renderer.resize(width, height);}game.world.setBounds(0, 0, width, height);game.camera.setSize(width, height);game.camera.setBoundsToWorld();game.scale.setShowAll();game.scale.refresh();

It's dealing more with resizing the browser window, but should be similar to your usage scenario. Hope it helps.

Share this post


Link to post
Share on other sites

Now that I think about it, do you know of a convenient way to actually find out about such specific functions? I know about Phaser's documents, but actually finding what you need can be pretty tricky, especially if you don't exactly know how to solve problem #whichever.

Share this post


Link to post
Share on other sites

I'm not sure there is an easy way for this (asking the forums here is actually the most convenient way), I am just searching the docs for whatever seems like it could do the trick, and if I'm not sure what it does I do a search "Phaser mysteryFunction" and usually posts from the forums or other tutorials come up.

 

Good thing is that Phaser has been around for awhile and its becoming more popular by the day, this helps because more and more search results come up. 

Share this post


Link to post
Share on other sites

I'm on OSX and I use this program called Dash. It's an offline documentation browser that has documentation for tons of things (HTML, JS, etc). Users can contribute docsets as well. There's a Phaser docset that's current to 2.4.3.

 

Once I learned my way around Phaser and learned the biggish component parts (ScaleManager, Phaser.Input, Phaser.Time, etc) it got easier to guess where stuff like this is located.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.