Game Development Community

Tile rendering issues

by William McDonald · in Torque X 2D · 06/22/2010 (8:29 pm) · 3 replies

We are having some issues with rendering tilemaps. The first thing we did was force Torque X to render the tile map using a point filter. That produced a result like so:
suckerfreegames.com/_kq/kq_fine.png

Unfortunately, when the camera starts to move, the tiles begin to tear:
suckerfreegames.com/_kq/kq_error.png

We've tried many different things, but we just can't get it to render without tearing. Has anybody else had this problem, and if so, were you ever able to fix it?

On the off-chance that it is the camera's position that is causing the issue, I could re-write the camera system to only take pixel coordinates. Could the camera be the issue?

About the author

I am the grand bureaucrat of SuckerFree Games. I now have one game in distribution, "Kobold's Quest" and another is soon to be published, "Dungeons the Eye of Draconus". My day job is as a Videographer.


#1
06/22/2010 (9:07 pm)
It's an issue with the tiles being between pixel boundaries. Point fixes the interpolation, but not this.

Say your resolution is at 1280x720 and your camera extent is 128x72, as long as you move your camera by multiples of .1, you should be fine. So basically, yeah the camera is the issue as it's moving stuff between the pixel boundaries.
#2
06/22/2010 (9:10 pm)
Yeah, I thought it might be a camera issue. I'll have a go at forcing the camera to use pixel positions to see if that fixes it.
#3
06/22/2010 (9:44 pm)
Okay, I was able to fix this. For future reference, here is my modified Position get method in T2DSceneCamera.cs:
public override Vector2 Position
{
    get
    {
        Vector2 ret;

        if (UseCameraWorldLimits)
        {
            // clamp the returned position to CameraWorldLimits (if used)
            ret = new Vector2(MathHelper.Clamp(base.Position.X, CameraWorldLimitMin.X, CameraWorldLimitMax.X),
                              MathHelper.Clamp(base.Position.Y, CameraWorldLimitMin.Y, CameraWorldLimitMax.Y));
        }
        else
        {
            ret = base.Position;
        }

        // Convert to pixel coordinates.
        // The following assumes your target resolution is 1280x720
        // and your camera size is 128x72.  In this case, we want to
        // return the position in increments of 0.1.
        ret.X = (float)Math.Round(ret.X * 10.0f, 0) / 10.0f;
        ret.Y = (float)Math.Round(ret.Y * 10.0f, 0) / 10.0f;
        return ret;
    }
    set
    {
        base.Position = value;
        _isMoving = false;
        _UpdateSceneRegion();
    }
}