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 8508889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:17:07+00:00 2026-06-11T03:17:07+00:00

I have a game where image Views changes on a timer. When a button

  • 0

I have a game where image Views changes on a timer. When a button is clicked (stop) the update is called to update score and spins. I need to stop when the whammy(); is called and run a frame animation then start the timer back when the animation has ended. I have tried to call sleep(2500); but it cause the everything to wait the 2.5 seconds and the frame animation then runs with the image view timer. That just won’t work for what I need. Below is the section of code I need help with:

    public void onClick(View v) {
    if (v.getId() == R.id.btstop) {
        final Button bstop = (Button) findViewById(R.id.btstop);
        bstop.setEnabled(false);
        updateState();
    }
}

/**
 * set random view. get random 1 point from class utils and display to 1
 * position random
 */
public void setRandomView() {
    int item = new Random().nextInt(18);
    current = Utils.getAPoint();
    int img = current.getImg();
    int score = current.getScore();
    int spin = current.getSpin();
    iv[item].setImageResource(img);
    dataPoint.get(item).setImg(img);
    dataPoint.get(item).setScore(score);
    dataPoint.get(item).setSpin(spin);
    ivcenter.setImageResource(img);

}

/**
 * display Name,score & spin to screen
 */
public void setPoint() {
    tvspin.setText(spins + "\n" + name);
    tvpoint.setText(point + "");
}

/**
 * Start Thread Sets the speed of the game board Enable STOP button to true
 * 
 * @param time
 */
public void start(int time) {
    countDownTimer = new CountDownTimer(time, 300) {

        @Override
        public void onTick(long millisUntilFinished) {
            // call to set random view
            setRandomView();

        }

        @Override
        public void onFinish() {
            // TODO Auto-generated method stub

        }
    }.start();

}

/**
 * stop timer thread
 */
public void stop() {
    try {
        countDownTimer.cancel();
    } catch (Exception e) {
        // TODO: handle exception
    } finally {
    }
}

/**
 * update state game and check what tile is in the center
 */
public void updateState() { // get score,spin current point
    int scoreCurrent = current.getScore();
    int spinCurrent = current.getSpin();
    spins--;// Take one from spins

    // if score = 2, that mean to double score
    if (scoreCurrent == 2) {
        point = point * 2;
        playmp3(R.raw.correct);
    }

    // if score = 0, that means tile is a whammy
    if (scoreCurrent == 0) {
        playmp3(R.raw.buzz);
        whammy();// I need to put everything else on hold here and animation here
        point = 0;// sets the score to 0
        whammy++; // Add a whammy to the whammy count

        // Display the whammy that was added
        for (int i = 0; i < whammy; i++) {
            popup[i].setVisibility(View.VISIBLE);
        }
        // sleep(2500);
        if (whammy == 4) {
            stop();
            stopmp3();
            callFinish();
        }
    }
    // else ,score = score current + point.getscore
    else {
        playmp3(R.raw.correct);
        point = point + scoreCurrent;
    }
    // spins--;// Take one from spint

    // if spin > 0, that mean is add a spin
    if (spinCurrent > 0) {
        spins = spins + spinCurrent;
    }
    setPoint(); // display spin,score and name to screen

    sleep(2000); // Adds a delay so that the whammy pop up can be seen

    // if spint >0 start new data random
    if (spins > 0) {
        stop();
        final Button bstop = (Button) findViewById(R.id.btstop);
        bstop.setEnabled(true);
        start(10000 * 60 * 60 * 24);
    } else {
        // stop all
        stop();
        stopmp3();
        // if spin < 2, that round <2 move to spin activity
        if (round < 2) {
            Intent it = new Intent(getBaseContext(), SpinActivity.class);
            startActivity(it);
            finish();
        }
        // else move to high score activity
        else {
            callFinish();
        }
    }
}

private void whammy() {
    // set up the whammy act animation
    final ImageView act = (ImageView) findViewById(R.id.whammyact);
    act.setBackgroundResource(R.drawable.tnt_animation);
    actAnim = (AnimationDrawable) act.getBackground();
    actAnim.setVisible(true, true);

}
  • 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-11T03:17:07+00:00Added an answer on June 11, 2026 at 3:17 am

    OK Here are the changes that were made to make the animation run and finish before the game timer gets started back…

    IF THERE ARE QUESTION OR ANYONE NEED HELP FEEL FREE TO ASK.

            if (scoreCurrent == 0) {
            countDownTimer.cancel();
            countDownTimer = null;
            // Use Timer to set visibility to GONE after the animation finishes.            
                        TimerTask timerTask = new TimerTask(){
                            @Override
                            public void run() {
                                PressActivity.this.runOnUiThread(new Runnable(){
                                    public void run() {
                                        resumeLogicAfterPress();
                                    }
                                });}};
                        Timer timer = new Timer();
                        timer.schedule(timerTask, getWhammyAnimationTotalDuration(actAnim));
        } else {
            resumeLogicAfterPress();
        }
    
    }
    
    public void resumeLogicAfterPress() {
        // Display the whammy that was added
                for (int i = 0; i < whammy; i++) {
                    popup[i].setVisibility(View.VISIBLE);
    
                }
    
    
                sleep(2500); //Adds a delay so that the whammy pop up can be seen
    
                //Start the background music
                playmp3(mpPress, R.raw.press);
                // if whammy = 4. stop all and move to high score
                if (whammy == 4) {
                    stop();
                    stopmp3();
                    callFinish();
                }
                // if spint >0 start new data random
                if (spint > 0) {
                    stop();
                    final Button bstop = (Button) findViewById(R.id.btstop);
                    bstop.setEnabled(true);
                    start(10000 * 60 * 60 * 24);
                } else {
                    // stop all
                    stop();
                    stopmp3();
                    // if spin < 2, that round <2 move to spin activity
                    if (spin < 2) {
                        Intent it = new Intent(getBaseContext(), SpinActivity.class);
                        startActivity(it);
                        finish();
                    }
                    // esle move to high score activity
                    else {
                        callFinish();
                    }
                }
    }
    
    private void whammy() {
        // set up the whammy act animation
        final ImageView act = (ImageView) findViewById(R.id.whammyact);
        act.setBackgroundResource(R.drawable.tnt_animation);
        actAnim = (AnimationDrawable) act.getBackground();
        actAnim.setVisible(true, true); 
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spot a difference game that every time I solve an image,
I am making a game where I have a back ground image of a
Update The reason I couldn't update properly was I didn't have game's jar file
I have a game where the number of ImageViews shown on the page need
I have an image view that I draw my game board in for my
I have a card game that I am developing and need to load card
I have an image of a basic game map. Think of it as just
I have a custom view called GameView where my game is drawn. There is
I develop a game that will have to load jpg images that now i
I'm developing a game. I want to have game entities each have their own

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.