开发者

Tile Collision Question

I'm working on tile collision. Currently, I just draw the tile map the normal way (two for loops) and there is no scrolling. Right now, to check if my player is over a tile, I use tileX = (int)person1v.X / 16; tileY = (int)person1v.Y / 16; However, I want to detect collision before I hit the tile so it could a开发者_开发知识库ct as a wall. How do I detect collision before even making the move?


If the player moves 3 pixels at a time then check for:

leftTile = (int)(person1v.x - 3) / 16;

And for the tile to the right:

rightTile = (int)(person1v.x + 3 + 16) / 16;


well instead of moving him first and checking for collision afterwards, check for collision for the future position of the character and if there is no collision then change the character's position.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜