Skip to content

Instantly share code, notes, and snippets.

@Ultima2876
Created April 8, 2015 04:14
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 Ultima2876/1be15d549703e79c6049 to your computer and use it in GitHub Desktop.
Save Ultima2876/1be15d549703e79c6049 to your computer and use it in GitHub Desktop.
// Set up scaling stuff. It's highly recommended that you copy this code to save yourself some headaches!
this.game.scale.scaleMode = Phaser.ScaleManager.USER_SCALE;
this.game.scale.pageAlignHorizontally = true;
this.game.scale.pageAlignVertically = true;
this.game.scale.forceOrientation(true, false);
// Scaling function that is called on resize or orientation change!
this.scalingFunction = function(self) {
self.scaleFactor = Math.min(window.innerWidth / self.game.width, window.innerHeight / self.game.height);
self.game.scale.setUserScale(self.scaleFactor, self.scaleFactor);
self.game.scale.refresh();
self.game.canvas.style.position = 'absolute';
self.game.canvas.style.top = ((window.innerHeight - (self.game.height * self.scaleFactor)) / 2) + 'px';
self.game.canvas.style.left = ((window.innerWidth - (self.game.width * self.scaleFactor)) / 2) + 'px';
}
// Resize on screen size changes (or orientation changes)
this.game.scale.setResizeCallback(function() {
this.scalingFunction(this);
}, this)
this.scalingFunction(this); // Set up initial scaling for devices that don't fire resize on start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment