Skip to content

Instantly share code, notes, and snippets.

@makzan
Created January 1, 2016 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save makzan/9b0b82d288ee3c40e296 to your computer and use it in GitHub Desktop.
Save makzan/9b0b82d288ee3c40e296 to your computer and use it in GitHub Desktop.
CreateJS starting point with Retina support
class App {
constructor() {
this.canvas = document.getElementById("app-canvas");
this.stage = new createjs.Stage(this.canvas);
this.retinalize();
createjs.Ticker.setFPS(60);
// keep redrawing the stage.
createjs.Ticker.on("tick", this.stage);
createjs.Touch.enable(this.stage);
}
retinalize() {
let originalCanvasWidth = this.canvas.width;
let originalCanvasHeight = this.canvas.height;
let ratio = window.devicePixelRatio;
if (ratio === undefined)
return;
let height = this.canvas.getAttribute('height');
let width = this.canvas.getAttribute('width');
this.canvas.setAttribute('width', Math.round( width * ratio ) );
this.canvas.setAttribute('height', Math.round( height * ratio ) );
// Set CSS
this.canvas.style.width = width+"px";
this.canvas.style.height = height+"px";
this.stage.scaleX = this.stage.scaleY = ratio;
// save original width & height into stage
this.stage.width = originalCanvasWidth;
this.stage.height = originalCanvasHeight;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment