我有2个按钮,我希望它们落在屏幕上,当它们到达指定的Y轴(411)时,它们会被隐藏并设置为NULL,然后HP标签被扣除-1点。但是当我使用if语句时,它会跳过屏幕上的另一个按钮。这是代码:
- (void)fall {
i += 1;
btn.center = (CGPointMake(btn.center.x, btn.center.y +5));
if (btn.center.y >= 411) {
btn.hidden = TRUE;
btn = NULL;
startBtn.enabled = TRUE;
hpLbl.text = [NSString stringWithFormat:@"%d", [hpLbl.text intValue]-1];
}
}
- (void)fall2 {
i += 1;
btn2.center = (CGPointMake(btn2.center.x, btn2.center.y +5));
if (btn2.center.y >= 411) {
btn2.hidden = TRUE;
btn2 = NULL;
startBtn.enabled = TRUE;
hpLbl.text = [NSString stringWithFormat:@"%d", [hpLbl.text intValue]-1];
}
}
就像我说的那样,fall =一个按钮,而fall2 =另一个按钮。错误发生在:
hpLbl.text = [NSString stringWithFormat:@"%d", [hpLbl.text intValue]-1];