2012-05-12 98 views
0

我有一个基于瓷砖的游戏。每个瓷砖纹理都被加载,然后我将每个瓷砖纹理相邻,形成一个连续的背景。我实际上按照这个教程的XML文件。XNA - 绘制缩放2D精灵

http://www.xnadevelopment.com/tutorials/looksleveltome/looksleveltome.shtml

纹理的来源为50x50。

然而,它只能它的比例为1(或更低),如果比例大于

结果:正常尺寸(50像素和规模1) http://imageshack.us/photo/my-images/525/smallzp.jpg/

更大的尺寸(缩小或100像素xml文件) http://imageshack.us/photo/my-images/577/largeki.jpg/

我们可以看到瓷砖之间存在线条,这些线条不在纹理中。它实际上不是那么糟糕这里,但在我的游戏地形设置,这就是它的作用: http://imageshack.us/photo/my-images/687/zoomedsize.png/

同样的效果是目前我是否增加在XML文件中的平铺尺寸,绘制时更改比例或使用我的相机放大。

//zoom code 
public Matrix GetTransformation() 
{ 
    return 
     Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) * 
     Matrix.CreateRotationZ(Rotation) * 
     Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) * 
     Matrix.CreateTranslation(new Vector3(_device.Viewport.Width * 0.5f, _device.Viewport.Height * 0.5f, 0)); 
} 

//draw 
_spriteBatch.Begin(SpriteSortMode.Immediate, 
    BlendState.AlphaBlend, null, null, null, null, 
    _camera.GetTransformation()); 

//for each tile 
theSpriteBatch.Draw(mSpriteTexture, Position, Source, 
    Color.Lerp(Color.White, Color.Transparent, mAlphaValue), 
    mRotation, new Vector2(mSource.Width/2, mSource.Height/2), 
    Scale, SpriteEffects.None, mDepth); 

这是有原因吗?一种方法来解决它放大时有连续的纹理?

回答

1

问题在于你的采样器状态,gpu试图采样点附近的颜色来插入它们。

在您的spriteBatch.Begin()中使用SamplerState.PointClamp,它将被修复。

+0

这是天才,它的作品!谢谢! – Amaranth