ios - NSTimer stops my image from moving -
when hold down on button image move direction.
the game objective going move image hit image, , i'm using nstimer.
then have nstimer because have 15 seconds on them hit other image. if don't game [self gameover] but, nstimer counts 15 seconds started , move image image moves bit , goes center again.
when delete countdown timer, image not go center after stop pressing button stops on current position.
and that's want while i'm using countdown timer well.
code:
-(void)goleft { ball.center = cgpointmake(ball.center.x -5, ball.center.y); } -(ibaction)left { goleft = [nstimer scheduledtimerwithtimeinterval:0.05 target:self selector:@selector(goleft) userinfo:nil repeats:yes]; if (goleft == nil) goleft = [nstimer scheduledtimerwithtimeinterval:0.05 target:self selector:@selector(goleft) userinfo:nil repeats:yes]; } -(ibaction)stopleft { [goleft invalidate]; goleft = nil; } //and heres timer : -(ibaction)docountdown: (id)sender;{ if (countdowntimer) return; remainingticks = 25; [self updatelabel]; countdowntimer = [nstimer scheduledtimerwithtimeinterval: 1.0 target: self selector: @selector(handletimertick) userinfo: nil repeats: yes]; } -(void)handletimertick { remainingticks--; [self updatelabel]; if (remainingticks <= 0) { [countdowntimer invalidate]; countdowntimer = nil; } } -(void)updatelabel { thelabel.text = [[nsnumber numberwithunsignedint: remainingticks] stringvalue]; }
Comments
Post a Comment