Created
April 8, 2015 04:14
-
-
Save Ultima2876/1be15d549703e79c6049 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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