开发者

Blitting with a camera leads to seams (due to floating point errors?)

开发者 https://www.devze.com 2023-03-30 01:30 出处:网络
I\'m working on a tilemap implementation with blitting (in Flash but I don\'t think it\'s language relevant).The problem I\'m having is that as I pan my camera around, 1 pixel seams start to become vi

I'm working on a tilemap implementation with blitting (in Flash but I don't think it's language relevant). The problem I'm having is that as I pan my camera around, 1 pixel seams start to become visible depending on the location.

Here's how I decide my blitting point:

var destination : Point = _position.toPoint();

if (camera != null)
{
    destination.x -= camera.position.x;
    destination.y -= camera.position.y;
}

// the actual blit, not really relevant:
canvas.bitmapData.copyPixels(_bitmapData, _sou开发者_Python百科rceRectangle, destination, null, null, true);

As I scroll my camera around, I can see the position becoming really wonky. Here's some traces:

     pre-camera: 443 534
     post-camera: 396.3333333333333 294
     pre-camera: 476 534
     post-camera: 429.3333333333333 294
     pre-camera: 509 534
     post-camera: 462.3333333333333 294

The seams only appear with those .3333333333 post camera positions.

Does it seem logical that these floating point issues are what's causing the seams? Is it safe to just floor / round the destination values since you can't blit to half a pixel anyways.

Thanks!

0

精彩评论

暂无评论...
验证码 换一张
取 消