fakeOne
2006.07.27, 01:43 AM
Hi.
I'm making a variation of pong in objc/cocoa and I need to make it so I can detect if the ballRect and the paddleRect intersect. This is something similiar to what I have so far..:
if (NSIntersectsRect(paddleRect, ballRect)) {
// bounce off!
dx = -dx; // dx, being the ballRect.origin.x
}
This works, but it's a bit buggy. The ball sometimes gets glitched to the paddle for a second. I also googled and found someone else having a similiar problem as me ( http://lists.apple.com/archives/Cocoa-dev/2004/Jan/msg01525.html ).
And I also tried doing dy = -dy (being ballRect.origin.y) too, but it just turned out to be a bit more buggy.
So my question is, would there be a better way of detecting if the rects intersect? Or some better way of doing this, so the ball doesn't glitch?
I'm making a variation of pong in objc/cocoa and I need to make it so I can detect if the ballRect and the paddleRect intersect. This is something similiar to what I have so far..:
if (NSIntersectsRect(paddleRect, ballRect)) {
// bounce off!
dx = -dx; // dx, being the ballRect.origin.x
}
This works, but it's a bit buggy. The ball sometimes gets glitched to the paddle for a second. I also googled and found someone else having a similiar problem as me ( http://lists.apple.com/archives/Cocoa-dev/2004/Jan/msg01525.html ).
And I also tried doing dy = -dy (being ballRect.origin.y) too, but it just turned out to be a bit more buggy.
So my question is, would there be a better way of detecting if the rects intersect? Or some better way of doing this, so the ball doesn't glitch?