【问题标题】:XNA - Drawing zoomed 2D spritesXNA - 绘制缩放的 2D 精灵
【发布时间】:2012-05-12 18:15:18
【问题描述】:

我有一个基于图块的游戏。每个瓦片纹理都被加载,然后我将每个瓦片贴在一起绘制,形成一个连续的背景。我实际上是按照这个教程来获取 xml 文件的。

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

纹理的来源是 50x50。

但是,它只有在比例为 1(或更低)时才有效,如果比例更大

结果:正常大小(50 像素和比例 1) http://imageshack.us/photo/my-images/525/smallzp.jpg/

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

我们可以看到瓷砖之间有线条,这些线条不在纹理中。这里实际上并没有那么糟糕,但是在我的游戏图块中,它就是这样做的: http://imageshack.us/photo/my-images/687/zoomedsize.png/

无论我在 xml 文件中增加 tile 大小、在绘图时更改比例还是使用我的相机进行缩放,都会出现相同的效果。

//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);

这是有原因的吗?有一种方法可以在缩放时将其修复为具有连续纹理?

【问题讨论】:

    标签: xna zooming textures


    【解决方案1】:

    问题在于您的采样器状态,gpu 正在尝试对点附近的颜色进行采样以对它们进行插值。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      • 2017-04-19
      • 1970-01-01
      相关资源
      最近更新 更多