iphone - How to detect UIImageView Collisions -


i wondering why code doesn't work. want ball (uiimageview) bounce off of block (also uiimageview). ball switches both x , y movements negative instead of one. wrong??? please help... here code

-(void)animateball:(nstimer *)thetimer {      collisioncount ++;     bouncyball.center = cgpointmake(bouncyball.center.x + ballmovement.x, bouncyball.center.y + ballmovement.y);      if (cgrectintersectsrect(bouncyball.frame, wallone.frame)) {         if (collisioncount >= 5) {             [self processcollision:wallone];             collisioncount = 0;         }     }      if (bouncyball.center.x > 313 || bouncyball.center.x < 8) {         ballmovement.x = -ballmovement.x;     }     if (bouncyball.center.y > 453 || bouncyball.center.y < 8) {         ballmovement.y = -ballmovement.y;     } }  -(void)processcollision:(uiimageview *)wall {      if (ballmovement.x > 0 && wall.frame.origin.x - bouncyball.center.x <= 4) {         ballmovement.x = -ballmovement.x;     }     else if (ballmovement.x < 0 && bouncyball.center.x - (wall.frame.origin.x + wall.frame.size.width) <= 4) {         ballmovement.x = -ballmovement.x;     }      if (ballmovement.y > 0 && wall.frame.origin.y - bouncyball.center.y <= 4) {         ballmovement.y = -ballmovement.y;     }     else if (ballmovement.y < 0 && bouncyball.center.y - (wall.frame.origin.y + wall.frame.size.height) <= 4) {         ballmovement.y = -ballmovement.y;     } } 

does happen when ball hits center of edge? anyway don't need handle 1 dimension @ time? can't third if else if?


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -