Quote:
Originally Posted by iSdkDev
@SMASHER OR ANY1ELSE "Ok soo i did this code and i have those images falling but there's a bug!I have a label that turns to 1 from 0 when that falling image collides with an image below BUT there is a bug when i starts falling down it just automatically adds 1 to my label where as i want tht 1 to add only when it collides!!Please help"
Here is the code
|
First, all of this [self performSelector] is not necessary. Just call [self change] and [self change1] . If that gives you warnings, then you're not declaring your methods in the .h like you should. That's probably not causing this problem, but it'll make everything more readable and save you other trouble.
Your CGRectIntersectsRect code looks OK. Do cloud and banana have the same immediate parent view, or is one of them the subview of some other subview? That would keep the frames from being compared correctly -- one would be in the wrong coordinate space.
If that's OK, then log the frames and tell me what you're getting.
Code:
if(CGRectIntersectsRect(cloud.frame, banana.frame)) {
NSLog(@"cloud %f,%f %f,%f", cloud.frame.origin.x, cloud.frame.origin.y, cloud.frame.size.width, cloud.frame.size.height);
NSLog(@"banana %f,%f %f,%f", banana.frame.origin.x, banana.frame.origin.y, banana.frame.size.width, banana.frame.size.height);
[self change];
mainInt += 1;
label.text = [NSString stringWithFormat:@"%d" , mainInt];
[self UpdateINT];
}
Also make sure this bit of code is really the problem; comment out mainInt+=1 and make sure the problem goes away.