在 libgdx 游戏中设置延迟

set a delay in libgdx game(在 libgdx 游戏中设置延迟)

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

问题描述

我有一个游戏(比如超级跳投,这个游戏是一个跳跃游戏),我们的角色有生命.与敌人碰撞后,他的生命减少.我想在 1 秒后计算碰撞.我的意思是在这 1 秒内,如果我的角色与敌人接触,什么都不会发生,他会继续前进.为此,我在 GameScreen 类中定义了一个布尔变量,名称为collision",在 Wolrd 类中定义另一个,名称为collBirds".在与敌人碰撞一次接触后,collBirds 变为 true.但我想在 1 秒碰撞后更改为假.我使用了一些东西,比如 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;
        }
    }

推荐答案

在某些情况下,您可能还想使用 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 游戏中设置延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 libgdx 游戏中设置延迟

基础教程推荐