XNA:有没有办法直接从图块集中绘制图块?

发布于 2024-12-26 09:35:52 字数 602 浏览 1 评论 0原文

详细说明: 我有一个包含 4 个图块 [32 x 32] 的图块集。为了便于举例,我们将它们称为泥土、草、沥青、水泥。
我想画一个相对较长的草表面[96 x 32]。有没有办法使用 XNA (LinearWarp) 的平铺机制来使用单个 Draw() 调用来绘制它们?

我尝试过:

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap,null,null);
GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
spriteBatch.Draw(_tileSetTexture /* 64 x 64 */, destRectangle/* 96 x 32*/, TileFrame /*32 x 32*/, Color.White, 0f , Vector2.Zero ,SpriteEffects.None, 0f);

我知道可以选择将每个图块裁剪为单独的Texture2D,然后使用源矩形的“扩展”来填充XNA LinearWrap,但我需要它们全部位于一个大的TileSet图像中,并执行尽可能简单。

To elaborate :
I have a tileset with 4 tiles [32 x 32]. For sake of the example let's call them Dirt, Grass, Asphalt, Cement.
I want to draw a relatively long surface of Grass [96 x 32]. Is there any way to use the tiling mechanism of XNA (LinearWarp) to draw them using single Draw() call ?

I tried:

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap,null,null);
GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
spriteBatch.Draw(_tileSetTexture /* 64 x 64 */, destRectangle/* 96 x 32*/, TileFrame /*32 x 32*/, Color.White, 0f , Vector2.Zero ,SpriteEffects.None, 0f);

I know that there's the option of cropping every tile to a separate Texture2D and later use the "extension" of the source rectangle for the XNA LinearWrap to fill, but I need them all to be in one big TileSet image, and perform it as simple as possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

臻嫒无言 2025-01-02 09:35:53

没有办法做到这一点,但好消息是也没有理由这样做。性能优势几乎可以肯定是完全可以忽略不计的。请记住,SpriteBatch.Draw() 调用并不是真正绘制任何东西;而是绘制任何东西。它将精灵信息添加到缓冲区的末尾,并且当您调用 SpriteBatch.End() 时,会立即绘制整个缓冲区。

您只需使用少量的精灵批次就可以多次用图块覆盖整​​个屏幕,这不会接近现代显卡的批次限制。

There's no way to do this, but the good news is that there's also no reason to do this. The performance benefit would almost certainly be completely negligible. Remember that a SpriteBatch.Draw() call isn't really drawing anything; it's adding sprite information onto the end of a buffer, and that entire buffer is drawn all at once when you call SpriteBatch.End().

You can cover the entire screen with tiles several times over using only a handful of sprite batches, which isn't going to come anywhere near the batch limit on a modern video card.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文