Pregunta

No conozco el término exacto para lo que estoy buscando. Estoy desarrollando un juego y estoy mostrando puntuación en otra escena del juego.Quiero cambiar el puntaje (en realidad, agregar el puntaje actual en el puntaje anterior) de tal manera que cambie uno por uno como en otros juegos. Por ejemplo, si el puntaje anterior en 10 y el puntaje actual es 10, entonces quiero mostrarlo así con una velocidad de 10 11 12 13 14 15 ... mientras agrega.Y cuando llegue a 20 se reproducirá un sonido como tiiiinnnnnnnn.Quiero agregar uno por uno. Espero haber aclarado mi pregunta, por favor brinde una solución. Gracias

¿Fue útil?

Solución

Otra forma que me funciona.

private TimerHandler timerHandler;
private long startTime = 120000; // 2 minutes for example

private void createTimer() {
    final float period = 1; //one second

    this.getEngine().registerUpdateHandler(timerHandler = new TimerHandler(period, new ITimerCallback() {                      
        public void onTimePassed(final TimerHandler pTimerHandler) {
            timerHandler.reset();

            startTime = (long) (startTime - (period * 1000));
            int seconds = (int) ((startTime / 1000) % 60);
            int minutes = (int) ((startTime / 1000) / 60);
            timerText.setText(String.format("%d:%02d", minutes, seconds));                            
        }
    }));
}

Otros consejos

Prueba esto,

Utilice texto modificable para su propósito,

ChangeableText textTime = new ChangeableText(int xPosition, int yPosition, Font mFont, "00");

luego inicie un temporizador y déle un retraso para la velocidad que desea cambiar

Ahora suponga que desea cambiar su texto de

int x= 10 a int y= 20

    final Timer timer = new Timer();
    timer.schedule(new TimerTask() {

            @Override
            public void run() {
                x++;
                textTime.setText(tm);
                if(x==y) {
                     timer.cancel();
                }
            }

    }, 0, 100); // you can change this delay with your own
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top