Firstly here is my .h files code where i declared everything...
@interface NextlLevel : UIViewController{
IBOutlet UIImageView *Coin1;
int score;
IBOutlet UILabel *scorelable;
}
@property (nonatomic, assign) int score;
@property (nonatomic, retain) IBOutlet UILabel *scorelable;
@end
I have also synthesised my implementations in my .m file here is the code...
@synthesize score;
@synthesize scorelable;
Secondly I have some code which just checks if my drag-able image has collided with a still image. Here is the code...
-(void) ifCollided {
if(CGRectIntersectsRect(Coin1.frame,MoneyBag.frame)){
Coin1.hidden = YES;
}
}
This code is just a basic way of checking for a collision but once the image has collided I want to add to a int which is displayed in a label. The only way i thought i could do this was by ...
firstly adding this line of code to 'ifCollided'
[self scorecheck];
So now 'ifCollided' looks something like this:
-(void) ifCollided {
if(CGRectIntersectsRect(Coin1.frame,MoneyBag.frame)){
Coin1.hidden = YES;
[self scorecheck];
}
}
Thirdly I had to make 'scorecheck' I did this by...
-(void)scorecheck{
score++;
scorelable.text = [NSString stringWithFormat:@"%i", score];
}
}
Here is a image to show that the code I'm currently using is not working correctly. And therefore is not just adding just one to the int that i set to 0. I'm displaying the int in the score label (at the top of my screen). Due to the code not correctly working as long as you touch, drag and hold whilst colliding in the boundaries of the image with the collission rule (in this case the moneybag)
Here is to the image i was talking about:
Any help would be very appreciated
Edit:Here is what i was meant to do in the void ifCollided
-(void) ifCollided {
if (!Coin1.hidden)
{
Coin1.hidden = YES;
[self scorecheck];
}
}
Thanks @Elliott Perry