Skip to content

Instantly share code, notes, and snippets.

@servercharlie
Created February 21, 2017 12:17
Show Gist options
  • Save servercharlie/fd157f69d1e94b97714c5ef674da1722 to your computer and use it in GitHub Desktop.
Save servercharlie/fd157f69d1e94b97714c5ef674da1722 to your computer and use it in GitHub Desktop.
Device scaling factorr, pixi / phaser..
var configuration = {
'render' : Phaser.CANVAS, // Render type
'canvas_width_max' : 2048, // The maximum width of the canvas
'canvas_width' : 1000, // The width of the canvas
'canvas_height_max' : 2048, // The maximum height of the canvas
'canvas_height' : 650, // The height of the canvas
'scale_ratio' : 1, // Scaling factor
'aspect_ratio' : 1, // Aspect ratio
};
// Calculate the scaling factor and the aspect ratio
configuration.canvas_width = window.screen.availWidth * window.devicePixelRatio;
configuration.canvas_height = window.screen.availHeight * window.devicePixelRatio;
configuration.aspect_ratio = configuration.canvas_width / configuration.canvas_height;
if (configuration.aspect_ratio < 1) configuration.scale_ratio = configuration.canvas_height / configuration.canvas_height_max;
else configuration.scale_ratio = configuration.canvas_width / configuration.canvas_width_max;
game = new Phaser.Game(configuration.canvas_width, configuration.canvas_height, configuration.render, 'gamewindow', { preload: preload, create: create, update: update, render: render });
player = game.add.sprite(game.world.centerX, game.world.centerY, 'player');
player.scale.set(configuration.scale_ratio);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment