平铺 2D 纹理以填充矩形 [英] Tiling a 2D Texture to Fill a Rectangle
问题描述
是否可以在 XNA 中平铺图像以填充整个矩形?我试过谷歌搜索这个主题,但我找不到任何似乎有用的东西(虽然我可能遗漏了一些明显的东西).我找到了 这个 MSDN 页面,但我似乎无法理解上班.这是我的代码:
Is it possible to tile an image in XNA so that it fills the entirety of a rectangle? I've tried Googling the subject, but I can't find anything that seems to work (I'm probably missing something obvious though). I found this MSDN page, but I can't seem to get it to work. Here's my code:
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null);
但这只是拉伸纹理以填充矩形,而不是平铺它.任何帮助表示赞赏.提前致谢.
But this just stretched the texture to fill the rectangle, not tile it. Any help is appreciated. Thanks in advance.
推荐答案
包裹采样器状态表示超出正常 0-1 范围的纹理坐标将被包裹.如果您使用空源矩形调用 Draw()
,那么您的纹理坐标将始终是从 0 到 1.
The wrap sampler states indicate that texture coordinates that fall outside of the normal 0-1 range will be wrapped. If you're calling Draw()
with a null source rectangle, then your texture coordinates are always going to be from exactly 0 to exactly 1.
尝试使用比纹理大的源矩形调用 Draw()
.两倍大应该平铺两次,四倍大应该平铺四次,以此类推.
Try calling Draw()
with a source rectangle that's bigger than the texture. Twice as big should tile it twice, four times as big should tile it four times, etc.
这篇关于平铺 2D 纹理以填充矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!