Skip to content

Instantly share code, notes, and snippets.

@foo9
Last active March 8, 2018 04:04
Show Gist options
  • Save foo9/8994609 to your computer and use it in GitHub Desktop.
Save foo9/8994609 to your computer and use it in GitHub Desktop.
pixi.js renderer resize
var STAGE_WIDTH = 320;
var STAGE_HEIGHT = 480;
var $window = $(window);
// XXX: debounce
$window.resize(onResize);
function onResize() {
var width;
var height;
var ratioWidth;
var ratioHeight;
var ratio;
width = $window.width();
height = $window.height();
ratioWidth = width / STAGE_WIDTH;
ratioHeight = height / STAGE_HEIGHT;
if (ratioWidth < ratioHeight) {
ratio = ratioWidth;
} else {
ratio = ratioHeight;
}
renderer.view.style.width = ~~(STAGE_WIDTH * ratio) + 'px';
renderer.view.style.height = ~~(STAGE_HEIGHT * ratio) + 'px';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment