0

我有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];
4

0 回答 0