Last active
March 8, 2018 04:04
-
-
Save foo9/8994609 to your computer and use it in GitHub Desktop.
pixi.js renderer resize
This file contains hidden or 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
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