开发者

XNA tearing when doing 2D camera transformations

I'm not sure why this is happening.

Basically I render my tile map to the screen using a Spritebatch with a matrix transformation, and I get this weird tearing thing happening. Tearing Note that everything looks fine when I render using Matrix.Identity.

This is the code that I use to create the Matrix: #region Creating Transformation private void CreateTransformation() { transformation = Matrix.Identity; Vector3 screenCenter = new Vector3 (graphics.Viewport.Width * 0.5f, graphics.Viewport.Height * 0.5f, 0f);

        transformation *= Matrix.CreateTranslation(-screenCenter); 
        transformation *= Matrix.CreateScale(zoom); 
        transformation *= Matrix.CreateTranslation(screen开发者_StackOverflow中文版Center); 
        transformation *= Matrix.CreateTranslation 
            (position.X * zoom, position.Y * zoom, 0f); 

        mustUpdateTransformation = false; 
    } 
    #endregion 

And this is the code that I use to begin the SpriteBatch:

        ScreenManager.SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None, camera.Transformation); 

And here is the code used to render each tile:

    public void Draw(SpriteBatch batch) 
    { 
        foreach (var layer in MapLayers) 
        { 
            foreach (Tile T in layer) 
            { 
                batch.Draw(T.SpriteSheet.Texture, T.Position, T.SpriteSheet.SourceRectangle(T.TileIndex), Color.White); 
            } 
        } 
    } 

Does anyone know what is happening?


Fixed, was doing something silly by representing pixel space as floats instead of integers.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜