我试图设置一个连接到图像的NSTimer,这样它只有在不与另一个图像交互时才有效

时间:2015-10-19 01:20:11

标签: ios objective-c nstimer

在.h文件中,我设置了if (hatSoundPlay){ //if hatSoundPlay is true hatsound.play(); //and a hatsound will play sticker sticker1 = new sticker();//creates a new sticker1 sticker1.arraysticker(hatPicture, "hat.png", clickX, clickY);//places sticker image ++;//increments image by 1 arraysticker[image] = sticker1;//puts sticker 4 into the array sticker11 = true; GoodguyBuilding12NSTimer方法。

falldown

在.m文件中,我设置了IBOutlet UIImageView *Goodguy; IBOutlet UIImageView *Building1; IBOutlet UIImageView *Building2; NSTimer *GoodguyFall; -(void)falldown; GoodguyFall,以及图片触及另一张图片时的代码,它会使NSTimer无效。如何设置定时器是有效的,因为它不会触及"建筑物"?

NSTimer

1 个答案:

答案 0 :(得分:0)

要在不触及建筑物后让Goodguy再次掉落,您需要安排另一个计时器。这可以通过

来完成
-(void)BuidlingMoving{
    if (CGRectIntersectsRect(Goodguy.frame, Building1.frame)){
        [GoodguyFall invalidate];
        GoodguyFall = nil;
    }
    else if (CGRectIntersectsRect(Goodguy.frame, Building2.frame)){
        [GoodguyFall invalidate];
        GoodguyFall = nil;
    } else if (GoodguyFall == nil) {
        GoodguyFall = [ NSTimer scheduledTimerWithTimeInterval: 0.03 target:self selector:@selector(falldown) userInfo:nil repeats:YES];
    }
}

在此解决方案中,我正在处理Goodguy不再与建筑物接触的情况。