Collision Detection between two rectangles
if (CGRectIntersectsRect(playerRect,wall)) {
//handle collision here
}
The problem I'm having is working out which side actually hit the w开发者_如何学Pythonall rectangle.
I need to know because then I stop te player from moving depending on which side hit. Thanks for any help DiscoI would add some direction property to my 'Player' object. This way when you detect a collision, you just check to see which way the player was moving prior to the collision and react accordingly.
Create a CGRect for each side of your object with just a width of 1 (or height of 1 depending on the side) and look for intersections with the sides instead of the entire object. If your object is moving faster than 1 pixel per collision check, then you would check the sides in addition to checking the entire object
精彩评论