Objective C: Boolean not working. Need outside opinion
When the user touches the screen, it looks at the boolean with an if and triggers a timer when value is NO
. It sets it to YES
so the user can't trigger it again when it's going. When the timer finishes what it's doing, it sets it back to NO
. The value is initialized in the viewDidLoad method. It works once, but will not work again. From the way things look, it SHOULD work. Can anyone see what's wrong with this:
- (void) fireLoop {
fireImage.hidden = 0;
fireImage.center = CGPointMake(fireImage.center.x, fireImage.center.y - 开发者_JAVA百科20);
if (fireImage.center.y == -5) {
[fireTimer invalidate];
fireImage.hidden = 1;
firedOn = NO;
}
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (firedOn == NO) {
firedOn = YES;
//set fire image position to player position
fireImage.center = CGPointMake(playerImage.center.x, playerImage.center.y);
fireTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/30 target:self selector:@selector(fireLoop) userInfo:nil repeats:YES];
}
}
You reset firedOn variable only if fireImage.center.y is exactly -5
- check if that it is really so. If not - you probably need to tweak that condition (check if y is less then -5 for example or if it lies in some interval instead of 1 exact value)
精彩评论