charlie_says Posted October 31, 2016 Share Posted October 31, 2016 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 More sharing options...
Alamantus Posted October 31, 2016 Share Posted October 31, 2016 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 More sharing options...
samme Posted October 31, 2016 Share Posted October 31, 2016 You might try ScaleManager#onSizeChange instead. Link to comment Share on other sites More sharing options...
charlie_says Posted October 31, 2016 Author Share Posted October 31, 2016 Thanks, but, I don't think that will do it - that's the signal that's triggered when the canvas is altered, not the function that's called... Link to comment Share on other sites More sharing options...
charlie_says Posted October 31, 2016 Author Share Posted October 31, 2016 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 More sharing options...
charlie_says Posted November 1, 2016 Author Share Posted November 1, 2016 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 More sharing options...
Recommended Posts