2

I am using NSTimer like this

  GameTimer=[NSTimer scheduledTimerWithTimeInterval:60.0/60.0 target:self selector:@selector(Move) userInfo:nil repeats:YES];

In the Move method I update the position of the view.

-(void)Move
{

CGRect OldPosition=self.JumbleWordView.frame;
CGRect NewPosition=CGRectMake(OldPosition.origin.x, OldPosition.origin.y+MovementPerSec, OldPosition.size.width, OldPosition.size.height);

[self.JumbleWordView setFrame:NewPosition];
if (NewPosition.origin.y>=Slot_Left*CurrentBlockSize)
{
    [self checkResult];
    [Mytimer invalidate];
if (!isAnswerCorrect)
{
    [self swapViews];
    TotalRowPenalty=TotalRowPenalty+1;
    Score=Score+RowIncompletePoints;
    ScoreLab.text=[NSString stringWithFormat:@"%d",Score];
}
[self LoadNextWord];

}

How do I go about pausing and resuming the Game timer?

Baby Groot
  • 4,637
  • 39
  • 52
  • 71
Desparado_
  • 605
  • 6
  • 7
  • Check this one, not best of all but can help you. [Timer not pausing](http://stackoverflow.com/questions/14101880/nstimer-pause-not-working/14102886#14102886) – Anoop Vaidya Apr 15 '13 at 06:14
  • You can't pause and resume a timer. You can instead invalidate it and create a new one when you need again.
    Take a look here: [here](http://stackoverflow.com/questions/12171990/pause-and-resume-nstimer)
    – Andrea Apr 15 '13 at 06:02
  • There is no direct method to pause NSTimer but you can save fire date and current date before invalidating the Timer. And when you resume it then create new NSTimer object and set fire date as the previously strored fire date. You can check these answers also for the similar problem. 1.[How to Pause/Play NSTimer?](http://stackoverflow.com/questions/9975562/how-to-pause-play-nstimer) 2.[how to pause and resume NSTimer in iphone](http://stackoverflow.com/questions/4144242/how-to-pause-and-resume-nstimer-in-iphone) Hope it helps you. – Nishant Tyagi Apr 15 '13 at 06:07

1 Answers1

1

there is no such thing as pause for NSTimer, you have to stop and start it again.

[GameTimer invalidate]; //will stop the timer after which you can start it again
SahilS
  • 396
  • 5
  • 7
Saurabh Passolia
  • 8,099
  • 1
  • 26
  • 41