在libgdx游戏中设置延迟 [英] set a delay in libgdx game

查看:105
本文介绍了在libgdx游戏中设置延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个游戏(如超级跳投,这个游戏是一个跳跃游戏),我们的角色有生命。在与敌人发生碰撞后,他的生命减少了。我想在1秒后计算碰撞。我的意思是在这1秒内,如果我的角色与敌人接触,没有任何事情发生,他继续他的方式。
为此,我在我的GameScreen类中定义一个布尔变量,名为collision,另一个在Wolrd类中定义,名称为collBirds。一次与敌人碰撞接触后,collBirds变为true。但我想在1秒后将collistion改为false。我使用System.currentTimeMillis()和for loop之类的东西,但没有任何反应。我在java中不太好。

i have a game(like super jumper, this game is a jumping game) that our character has life. after collision with enemies, his life reduce. and i want to after 1 sec , calculate the collisions. i mean in this 1 sec, if my character contact with enemies , nothing happen and he continue his way. for this , i define a boolean variable in my GameScreen class, name "collision" and another in Wolrd class, name "collBirds". after one contact with enemy collision and collBirds change to true. but i want after 1 sec collistion change to false. i use several things like System.currentTimeMillis() and "for loop",and nothing happen. i'm not so good in java.

这是我的条件:

if(World.collBirds == true && collition == false){
        life -= 1;
        lifeString = "Life : " + life;
        World.collBirds = false;
        collition = true;
        for (??? "need to stay here for 1 sec" ???) {
            collition = false;
        }
    }


推荐答案

In在某些情况下,您可能还想使用 com.badlogic.gdx.utils.Timer

In some cases you could also want to use com.badlogic.gdx.utils.Timer

示例用法:

float delay = 1; // seconds

Timer.schedule(new Task(){
    @Override
    public void run() {
        // Do your work
    }
}, delay);

这篇关于在libgdx游戏中设置延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆