在.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;
,Goodguy
和Building1
,2
和NSTimer
方法。
falldown
在.m文件中,我设置了IBOutlet UIImageView *Goodguy;
IBOutlet UIImageView *Building1;
IBOutlet UIImageView *Building2;
NSTimer *GoodguyFall;
-(void)falldown;
GoodguyFall
,以及图片触及另一张图片时的代码,它会使NSTimer
无效。如何设置定时器是有效的,因为它不会触及"建筑物"?
NSTimer
答案 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
不再与建筑物接触的情况。