Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9078245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:34:17+00:00 2026-06-16T19:34:17+00:00

I hope this is not a dumb question, since I’ve already googled and read

  • 0

I hope this is not a dumb question, since I’ve already googled and read a lot of other similar questions, but I have been messing around with this issue for days.

I have implemented a countdown timer using NSTimer and UIProgressView, but I want to do more with this time, i.e. play an alert sound when the timer reaches the last 10 seconds.

Here’s what I’ve done:

-(void) updateTimer
{
    if (time <= 0.0f)
    {

     //Invalidate timer when time reaches 0
         [timer invalidate];
         [[AudioManager sharedManager] muteGameClock1Sound];    
         [self showGameOverViewController];
     }
     else
     {
         time -= 0.1;
         [timeProgressView setProgress:time/totalTime animated:YES];

         if (time < 10 && pauseView)
         {
            [[AudioManager sharedManager] playGameClock1Sound];
         }
     }

}

and in the viewDidLoad:

timeProgressView.progress = 1;
time = [ConfigFileManager sharedManager].timePerQuestion.intValue * [DatabaseManager sharedManager].numberOfQuestions;
totalTime = [ConfigFileManager sharedManager].timePerQuestion.intValue * [DatabaseManager sharedManager].numberOfQuestions;
timer = [NSTimer scheduledTimerWithTimeInterval: 0.1f target: self             selector: @selector(updateTimer) userInfo: nil repeats: YES];

and the pauseGame method:

-(IBAction)pauseGame:(id)sender
{
    self.view.backgroundColor = [UIColor colorWithWhite: 0.0 alpha: 0.4];   
    pauseView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 250, 150)];
    pauseView.backgroundColor = [UIColor colorWithWhite: 0.0 alpha: 0.4];
    pauseView.center = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2);
    pauseView.clipsToBounds = YES;
    if ([pauseView.layer respondsToSelector: @selector(setCornerRadius:)])
        [(id) pauseView.layer setCornerRadius: 10];

    resumeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    resumeButton.center = CGPointMake(pauseView.bounds.size.width/4, pauseView.bounds.size.height/2);
    [resumeButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackground] forState:UIControlStateNormal];
    [resumeButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackgroundSelected] forState:UIControlStateSelected];
    [resumeButton setImage:[UIImage imageNamed:[ConfigFileManager sharedManager].messageResumeButton] forState:UIControlStateNormal];
    [resumeButton addTarget:self action:@selector(resumeTheGame) forControlEvents:UIControlEventTouchUpInside];

    restartButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    restartButton.center = CGPointMake(pauseView.bounds.size.width/2, pauseView.bounds.size.height/2);
    [restartButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackground] forState:UIControlStateNormal];
    [restartButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackgroundSelected] forState:UIControlStateSelected];
    [restartButton setImage:[UIImage imageNamed:[ConfigFileManager sharedManager].messageReplayButton] forState:UIControlStateNormal];

    [restartButton addTarget:self action:@selector(restartTheGame) forControlEvents:UIControlEventTouchUpInside];

    quitButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    quitButton.center = CGPointMake(pauseView.bounds.size.width*3/4, pauseView.bounds.size.height/2);
    [quitButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackground] forState:UIControlStateNormal];
    [quitButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackgroundSelected] forState:UIControlStateSelected];
    [quitButton setImage:[UIImage imageNamed:[ConfigFileManager sharedManager].messageQuitButton] forState:UIControlStateNormal];

    [quitButton addTarget:self action:@selector(showGameOverViewController) forControlEvents:UIControlEventTouchUpInside];

    [pauseView addSubview:resumeButton];
    [pauseView addSubview:restartButton];
    [pauseView addSubview:quitButton];
    [self.view addSubview: pauseView];
    choice1Button.userInteractionEnabled = NO;
    choice2Button.userInteractionEnabled = NO;
    choice3Button.userInteractionEnabled = NO;
    choice4Button.userInteractionEnabled = NO;
    choice5Button.userInteractionEnabled = NO;
    pauseButton.userInteractionEnabled = NO;

}

The problem is that the playGameClock1Sound method is not being called in this way, but it is, when I say: if (!pauseView && time > 10) which is not rational, and then in this case, when the pauseButton is pressed and therefore the pauseView is TRUE, the playGameClock1Sound method is being called again.

I’d be really grateful if someone helps me with this stupid issue, and even more grateful if you tell me how to handle pause/resume, too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:34:18+00:00Added an answer on June 16, 2026 at 7:34 pm

    Can you show how pauseView is set? If you try something like this it may be simpler…

    Everything you are doing seems fine so i think the issue is with how you are setting the pauseView bool.

    Also, is the audio file you are playing shorter then or equal to the timers delay time? If it is not it will be played again before it is finished.

    -(void) updateTimer
    {
        //stop counting if the view is paused
        if(pauseView)
        {
            return;
        }
    
        //done
        if (time <= 0.0f)
        {
            //Invalidate timer when time reaches 0
            [timer invalidate];
            [[AudioManager sharedManager] muteGameClock1Sound]; 
            [self showGameOverViewController];
        }
        else
        {
            time -= 0.1;
            [timeProgressView setProgress:time/totalTime animated:YES]; 
            if (time < 10)
            {
                NSLog("Play some audio");
                [[AudioManager sharedManager] playGameClock1Sound];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope this is not a dumb question but I really can't find anything
PHP/HTML Question I hope this is not a dumb question but I am trying
I really hope this is not a question posed by millions of newbies, but
Hope this question is not stupid since I am an amateur web designer. I
I hope this question is not a duplicate but I didn't find anything equivalent
I hope this question will not be rejected as there is no code. But
This is not a programming question but I hope Microsoft programmer can see this
am sorry for this dumb question, but am really confused; and i hope you'll
I expect this is a dumb question but I'm not the best when it
I hope this is not an duplicate question, but a quick search didn't give

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.