平铺 2D 纹理以填充矩形
是否可以在 XNA 中平铺图像以使其填充整个矩形?我尝试过谷歌搜索这个主题,但我找不到任何似乎有效的东西(不过我可能错过了一些明显的东西)。我找到了 此 MSDN 页面,但我似乎无法获取它去工作。这是我的代码:
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null);
但这只是拉伸纹理以填充矩形,而不是平铺它。任何帮助表示赞赏。提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
环绕采样器状态指示超出正常 0-1 范围的纹理坐标将被环绕。如果您使用空源矩形调用
Draw()
,则纹理坐标始终从 0 到 1。尝试使用以下命令调用
Draw()
比纹理大的源矩形。两倍大的应该瓷砖两次,四倍大的应该瓷砖四次,依此类推。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.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.