0

タイマーで画像ビューが変化するゲームがあります。ボタンをクリック (停止) すると、更新が呼び出されてスコアとスピンが更新されます。whammy(); のときに停止する必要があります。が呼び出されてフレーム アニメーションを実行し、アニメーションが終了したらタイマーを開始します。sleep(2500); を呼び出そうとしました。ただし、すべてが2.5秒待機し、フレームアニメーションが画像ビュータイマーで実行されます。それは私が必要とするものにはうまくいきません。以下は、助けが必要なコードのセクションです。

    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);

}
4

1 に答える 1

0

OK ここでは、ゲーム タイマーが開始される前にアニメーションを実行して終了させるために行われた変更を示します...

質問がある場合、または誰かが助けを必要とする場合は、お気軽にお問い合わせください。

        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); 
    }
于 2012-09-07T17:18:44.580 に答える