Created
January 1, 2016 05:05
-
-
Save makzan/9b0b82d288ee3c40e296 to your computer and use it in GitHub Desktop.
CreateJS starting point with Retina support
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
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