javascript - Update non-retina canvas app to retina display - Stack Overflow

I have an iPad 2 canvas app (game) and would like to get it to run on the new iPad retina display. Simp

I have an iPad 2 canvas app (game) and would like to get it to run on the new iPad retina display.

Simply put, what is the best method to stretch/shrink my iPad2 image for retina iPad models?

From the googling I've done, I've seen various methods but many include starting with retina sized images and scaling done.

I've also heard the performance of pushing retina quality sized pixels to the screen is slow, and that it is better to use iPad size images at the expense of some quality.

As it is right now, on the new iPad I see the top left quarter of my app, which makes sense, but performance is shocking pared to iPad 2.

Techniques I've seen include CSS media queries, using the pixel density, and CSS transforms - which are apparently quite fast.

Thanks

I have an iPad 2 canvas app (game) and would like to get it to run on the new iPad retina display.

Simply put, what is the best method to stretch/shrink my iPad2 image for retina iPad models?

From the googling I've done, I've seen various methods but many include starting with retina sized images and scaling done.

I've also heard the performance of pushing retina quality sized pixels to the screen is slow, and that it is better to use iPad size images at the expense of some quality.

As it is right now, on the new iPad I see the top left quarter of my app, which makes sense, but performance is shocking pared to iPad 2.

Techniques I've seen include CSS media queries, using the pixel density, and CSS transforms - which are apparently quite fast.

Thanks

Share Improve this question edited Feb 20, 2013 at 21:24 Jarrod asked Jun 22, 2012 at 20:04 JarrodJarrod 9,4655 gold badges60 silver badges73 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

I've put together a simple function to handle this problem. Basically, it takes the current canvas size and scales it by the device-pixel-ratio, shrinking it back down using CSS. It then scales the context by the ratio so all your original functions work as usual.

You can give it a shot and see how performance fares. If it isn't what you hoped for, you can just remove it.

function enhanceContext(canvas, context) {
    var ratio = window.devicePixelRatio || 1,
        width = canvas.width,
        height = canvas.height;

    if (ratio > 1) {
        canvas.width = width * ratio;
        canvas.height = height * ratio;
        canvas.style.width = width + "px";
        canvas.style.height = height + "px";
        context.scale(ratio, ratio);
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745371804a4624827.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信