XNA:有没有办法直接从图块集中绘制图块?
详细说明: 我有一个包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有办法做到这一点,但好消息是也没有理由这样做。性能优势几乎可以肯定是完全可以忽略不计的。请记住,
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 callSpriteBatch.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.