像其他游戏一样动态改变 AndEngine 中的分数

发布于 2024-12-26 02:52:59 字数 216 浏览 0 评论 0原文

我不知道我正在寻找的确切术语。 我正在开发一款游戏,并在其他游戏场景中显示分数。我想改变分数(实际上是在以前的分数中添加当前分数),就像在其他游戏中一样,一一改变。 例如,如果以前的分数为 10,当前分数为 10,那么我想在添加时以速度 10 11 12 13 14 15... 来显示它。当达到 20 时,将播放类似 tiiiinnnnnnnn 的声音。我想一一补充。 我希望我解决了我的问题,请提供解决方案。 谢谢

I don't know the exact term for what I am looking for.
I am developing a game and I am showing score in other game scene. I want to change the score (Actually add current score in previous score) in such a way that is change one by one like in other games.
For example if previous score in 10 and current score is 10 then I want to show it like this with speed 10 11 12 13 14 15... while adding. And when reached 20 a sound will be played like tiiiinnnnnnnn. I want to add one by one.
I hope I cleared my question please provide a solution.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄暮涼年 2025-01-02 02:52:59

尝试一下,

使用可更改的文本来达到您的目的,

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

然后启动一个计时器并按照您想要的更改速度给予延迟

现在假设您要将文本从

int x = 10 更改为 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

Try this,

Use Changeable text for your purpose,

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

then start a timer and give it delay for the speed you want to for changing

Now suppose you want to change your text from

int x = 10 to 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
柠檬色的秋千 2025-01-02 02:52:59

另一种对我有用的方法。

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

Another way that works for me.

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));                            
        }
    }));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文