Jump to content

onResize called repeatedly


charlie_says
 Share

Recommended Posts

I'm trying to make a dynamically sized game. It seems that setting

game.scale.scaleMode = Phaser.ScaleManager.USER_SCALE;

would be the way to go.

and then using

in the create function of each state I add this:

game.scale.onResize = this.onResize;

then add in the function

onResize: function () 
{
	console.log('menu RESIZE');
	
	game.scale.setGameSize(200, 250); 
		  
}

 

which correctly resizes the game. BUT, it also seems to keep recalling itself each time. I've set the style of the parent div to have no paddings/margin, but I can't work out why it doesn't only call once (if I comment out the setGameSize code, then the function only calls one.)

Any ideas where I'm going wrong?

Link to comment
Share on other sites

I don't think there is a game.scale.onResize function that you can set (at least, I don't see it in the current Phaser version's documentation anywhere), but there is a game.scale.onSizeChange Signal that you should be able to use like this:

game.scale.onSizeChange.add(this.onResize);

// Or maybe this, actually. I'm not sure which off the top of my head:
game.scale.onSizeChange.add(function () {
  this.onResize();
}, this);

Or maybe even using the game.scale.setResizeCallback() method, since that's what the documentation's game.scale.scaleMode entry mentions:

game.scale.setResizeCallback(function () {
    this.onResize();
}, this);

 

Maybe these would work better?

Link to comment
Share on other sites

it needs to be set as

game.scale.scaleMode = Phaser.ScaleManager.RESIZE;

not USER_SIZE

as per line 999 in ScaleManager.js

if (this.currentScaleMode === Phaser.ScaleManager.RESIZE)

typically this didn't fix

game.scale.setGameSize(200, 250); 

firing repeatedly, but

game.width = 200;
game.height = 250;

has the desired effect.

 

 

 

Link to comment
Share on other sites

apologies @Alamantus for some reason your post got lost... (I only got the mail this morning.)

so

game.scale.onResize = this.onResize;

does work, but, it also loses the context, so after you resize a couple of times it fails.

game.scale.onSizeChange.add(this.onResize, this);

as you'd suggested works properly. (You can do it as  an anonymous fn, but it's not necessary.)

Link to comment
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...
 Share

  • Recently Browsing   0 members

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