Tile based collision in XNA

本秂侑毒 提交于 2019-11-30 05:32:23

问题


I have drawn tiles in my XNA game and loaded my character. My character, however, doesn't move- the map does, which gives it the illusion of movement. Now I am wondering how to actually test against them for collision. I mean, where does the collision code go and how do I make all tiles represent 'one big thing'?


回答1:


There's a tutorial on pixel based collision detection on XNA Creator's club. You'll need to figure out what objects you want to do collision detection on. I guess you want the character to move across the tiled background, so you don't want to check for collision between your character and the background. Instead you should make any obstacle s sprites and do collision detection on those.




回答2:


You might have a look at Nick Gravelyn's Tile Engine Tutorials, it goes through the whole process of creating a tile engine. There's a link here to see all the tutorials on YouTube.




回答3:


You could have a look at the Platformer Starter Kit, it shows how to organize tiles in a map and check for collisions.




回答4:


Rectangles have a intersects method. If your player is centered and you know the coordinates, loop through the other texture2ds and check for an intersection before scrolling the map.



来源:https://stackoverflow.com/questions/2316133/tile-based-collision-in-xna

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!