Hello,
I am experimenting with CGRects and am trying to work on some simple collision detection. Here is my problematic mouseDragged: code
(Note that I haven't implemented dragging collision for anotherRect yet. I'm just waiting to find a good way to do it.)
Everything is great until an actual collision occurs. Once a collision happens, I can no longer drag myRect anymore. This is because rectCollision is ticked to true. Is there a way to see if myRect is moving away from the other rect, so that I can untick rectCollision to false?
Hopefully my question isn't too incoherent.
Thanks!
I am experimenting with CGRects and am trying to work on some simple collision detection. Here is my problematic mouseDragged: code
Code:
-(void)mouseDragged:(NSEvent *)theEvent{
NSPoint eventLocation = [theEvent locationInWindow];
NSPoint location = [self convertPoint:eventLocation fromView:self];
int locationX = location.x;
int locationY = location.y;
[self setNeedsDisplay:TRUE];
if (CGRectIntersectsRect(myRect, anotherRect)==true) {
NSLog(@"Two rects collide");
rectCollision = true;
}else{
rectCollision = false;
}
if(rectCollision == false){
if(isInMyRect == true){
myRect.origin.x = (locationX-50);
myRect.origin.y = (locationY-50);
}
}
if (isInAnotherRect == true) {
anotherRect.origin.x = (locationX-50);
anotherRect.origin.y = (locationY-50);
}
}
(Note that I haven't implemented dragging collision for anotherRect yet. I'm just waiting to find a good way to do it.)
Everything is great until an actual collision occurs. Once a collision happens, I can no longer drag myRect anymore. This is because rectCollision is ticked to true. Is there a way to see if myRect is moving away from the other rect, so that I can untick rectCollision to false?
Hopefully my question isn't too incoherent.
Thanks!