简体   繁体   中英

problem with the counter of a collision between two images

here is my code:

-(void)collision {

    if(CGRectIntersectsRect(imageView.frame,centre.frame)){

        [imageView removeFromSuperview];
        count++;
        label.text= [NSString stringWithFormat:@"%d", count];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];

    [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(collision) userInfo:nil repeats:YES];

    count=0;    
    scale=1;
}

with this code my count increase of more than one sometimes 34 and sometime 74 or 70, why?

Stops the receiver from ever firing again and requests its removal from its run loop.

 - (void)invalidate

class reference

helpful question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM