Hey all,
I'm having a problem using CGPointMake with CGRectIntersectsRect. When I move imageview itemtoss over imageview rightbox the collision is only detected if itemtoss's CGPointMake coordinates are contained within rightbox's frame. However, If itemtoss passes over rightbox in a CGPointMake animation, and itemtoss comes to rest at a point outside of the rightbox frame, no collision is detected. Can anyone think of a work around to detect a collision when the frames are "intersected" through a CGPointMake animation? I know I could move my imageview itemtoss in a chain of small increments but I like the fluidity of the one CGPointMake animation.
Thanks,
Nick
I'm having a problem using CGPointMake with CGRectIntersectsRect. When I move imageview itemtoss over imageview rightbox the collision is only detected if itemtoss's CGPointMake coordinates are contained within rightbox's frame. However, If itemtoss passes over rightbox in a CGPointMake animation, and itemtoss comes to rest at a point outside of the rightbox frame, no collision is detected. Can anyone think of a work around to detect a collision when the frames are "intersected" through a CGPointMake animation? I know I could move my imageview itemtoss in a chain of small increments but I like the fluidity of the one CGPointMake animation.
Code:
// car is an image view and newy is an int
-(IBAction)tossright{
flight = CGPointMake(newy-40, car.center.y-250);
itemtoss.center = flight;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.];
[UIView setAnimationDelay:0.0];
itemtoss.center = CGPointMake(newy+1000,car.center.y-400);
[UIView commitAnimations];
-(void)collisioncheck{
if (CGRectIntersectsRect(itemtoss.frame, rightbox.frame))
{
NSLog(@"yes");
itemtoss.hidden=YES;
// collision!!
}
}
- (void)viewDidLoad {
[NSTimer scheduledTimerWithTimeInterval:.02
target:self
selector:@selector(collisioncheck)
userInfo:nil
repeats:YES];}
Thanks,
Nick