Skip to content

Instantly share code, notes, and snippets.

@makzan
Created October 20, 2015 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makzan/7d4f432f24dc60cf61ca to your computer and use it in GitHub Desktop.
Save makzan/7d4f432f24dc60cf61ca to your computer and use it in GitHub Desktop.
Utility: Retina for CreateJS
This is a utility to make CreateJS canvas responds to retina display.
this.utility ?= {}
this.utility.retinalize = (stage, updateCSS=true) ->
canvas = stage.canvas
utility.originalCanvasWidth = canvas.width
utility.originalCanvasHeight = canvas.height
return unless window.devicePixelRatio
ratio = window.devicePixelRatio
height = canvas.getAttribute('height')
width = canvas.getAttribute('width')
canvas.setAttribute 'width', Math.round( width * ratio )
canvas.setAttribute 'height', Math.round( height * ratio )
if updateCSS
canvas.style.width = width+"px"
canvas.style.height = height+"px"
stage.scaleX = stage.scaleY = ratio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment