html5 canvas game - how to add retina support

前端 未结 3 1108
没有蜡笔的小新
没有蜡笔的小新 2021-02-20 13:07

I\'m creating an HTML5 canvas game for iPhone. I would like to support both retina and non-retina displays.

My question is, how do I support both retina and non-retina d

3条回答
  •  深忆病人
    2021-02-20 13:30

    A new article has just been published on the topic over at html5rocks.com:

    • HIGH DPI CANVAS

    upsize your canvas width and height by devicePixelRatio / webkitBackingStorePixelRatio and then use CSS to scale it back down to the logical pixel size you want. Taking our above case where Chrome reports a webkitBackingStorePixelRatio of 1 and a devicePixelRatio of 2 we would scale the dimensions of the canvas by 2 / 1, i.e. multiply them by 2, then we would use CSS to scale it back down.

提交回复
热议问题