Skip to content

Instantly share code, notes, and snippets.

@leigh-johnson
Created January 6, 2015 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leigh-johnson/511be9d4a3c54717da2f to your computer and use it in GitHub Desktop.
Save leigh-johnson/511be9d4a3c54717da2f to your computer and use it in GitHub Desktop.
OnEvent resize + handler to dynamically resize WebGL & Canvas element in Phaser.js
//add to game init
$(window).resize(function() { window.resizeGame(); } );
//add this function to main.js
function resizeGame() {
var height = $(window).height();
var width = $(window).width();
game.width = width;
game.height = height;
game.stage.bounds.width = width;
game.stage.bounds.height = height;
if (game.renderType === Phaser.WEBGL)
{
game.renderer.resize(width, height);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment