与瓷砖的碰撞检测
好吧,我通过以下代码在地图上绘制了图块:
for (int x = 0; x < WindowsWidth + TextureWidth; x += TextureWidth)
{
for (int y = 400; y < WindowsHeight; y += TextureHeight)
{
spriteBatch.Draw(Texture, new Rectangle((int)x, (int)y, TextureWidth, TextureHeight), Color.White);
}
}
我希望这段代码是好的,如果不好,我想听听您对此的评论。
好吧,所以我不知道如何使用这些图块和我的播放器进行矩形碰撞检测。
如果您需要其他解释,请评论,谢谢。
Alright, so I drew tiles on my map by the following code:
for (int x = 0; x < WindowsWidth + TextureWidth; x += TextureWidth)
{
for (int y = 400; y < WindowsHeight; y += TextureHeight)
{
spriteBatch.Draw(Texture, new Rectangle((int)x, (int)y, TextureWidth, TextureHeight), Color.White);
}
}
I hope this code is good, if not, I'd like to hear your comments about it please.
Alright, so I don't know how can I make a rectangle collision detection with those tiles and my player.
Comment if you need another explanation for anything, thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要简单的矩形碰撞检测,矩形对象有一个非常好的方法可以帮助您实现此目的(矩形.相交)。拿起你的图块并将它们与你角色的矩形相交。您需要进行优化,不要检查地图中的每个图块。因为听起来您是新手,所以您应该查看 Nick Gravelyn 的 Tile Engine 教程。 第一部分位于 YouTube 上。
http://msdn.microsoft.com/en-us/library/bb464123.aspx
If you want simple rectangular collision detection, the Rectangle objects have a really nice method to help you with this (Rectangle.Intersects). Take your tiles and intersect them with the rectangle of your character. You'll want to optimize to not check EVERY tile in the map. Since it sounds like you are new, you should check out Nick Gravelyn's Tile Engine Tutorials. The first part is here on YouTube.
http://msdn.microsoft.com/en-us/library/bb464123.aspx