Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何检测精灵是否为´;我在一定的时间间隔内没有碰过_Java_Android_Libgdx - Fatal编程技术网

Java 如何检测精灵是否为´;我在一定的时间间隔内没有碰过

Java 如何检测精灵是否为´;我在一定的时间间隔内没有碰过,java,android,libgdx,Java,Android,Libgdx,很抱歉,下面的问题非常具体,但我想用一个多小时来解决我的问题:一个精灵每3秒改变一次颜色。我可以检测用户是否点击了正确的颜色,但我无法检测用户是否只是在等待下一个颜色评分。我尝试了以下代码: private float timeSeconds = 0f; private float period = 3f; timeSeconds += Gdx.graphics.getRawDeltaTime(); for (int i=0;i<4;i++) { i

很抱歉,下面的问题非常具体,但我想用一个多小时来解决我的问题:一个精灵每3秒改变一次颜色。我可以检测用户是否点击了正确的颜色,但我无法检测用户是否只是在等待下一个颜色评分。我尝试了以下代码:

private float timeSeconds = 0f;
private float period = 3f;
timeSeconds += Gdx.graphics.getRawDeltaTime();    
for (int i=0;i<4;i++) {
                if (executed == true && !(sprite[zahl[i]].getBoundingRectangle().contains(touchPoint.x,
                        touchPoint.y))&& timeSeconds==0 && zahl[4] != zahl[i]) {
                    timeSeconds = 0;
                    this.dispose();
                    game.setScreen(new GameOverScreen(game, Integer.parseInt(score)));
                    return;
                }
            }
private float timeSeconds=0f;
私人浮动期=3f;
timeSeconds+=Gdx.graphics.getRawDeltaTime();

对于(int i=0;i你的要求有点难以理解,但我认为你的目标是让用户在3秒内至少触摸屏幕一次。如果用户在这段时间内没有触摸,则显示屏幕上的游戏。如果用户触摸了屏幕并触摸了正确的颜色精灵,则增加3秒触摸时间。如果用户有触摸,则增加3秒触摸时间至少触发了一个右精灵,并且在3秒内未能触摸,移动到水平完成屏幕

让我们以游戏屏幕为起点。此屏幕应显示游戏对象、分数和布尔值,以说明游戏是否结束或完成。然后,您可以通过以下方式调用游戏屏幕:

GameOverScreen(game,score,true); // game completed or
GameOverScreen(game,score,false); // game over
现在我们已经完成了结束屏幕,我们可以在游戏中添加一个名为lastTouched的计时器:

float lastTouched = 3f; // 3 seconds of touch time
接下来,我们添加一个布尔值,以便知道用户是否触摸了至少一个正确的颜色精灵:

boolean atLeastOneTouched = false;
现在,我们用以下方法降低每帧的计时器:

lastTouched -= Gdx.graphics.getRawDeltaTime();
我们会像往常一样检查您的雪碧触控,而不使用计时器:

for (int i=0;i<4;i++) {
            if (executed == true && !(sprite[zahl[i]].getBoundingRectangle().contains(touchPoint.x,
                    touchPoint.y)) && zahl[4] != zahl[i]) {
               // touched right colour
               atLeastOneTouched = true;
               lastTouched = 3f; // reset timer
            }
        }

for(int i=0;iI)假设存在某种计时器,因此当触摸到正确的对象时,将布尔值设置为true。当计时器结束时,如果为true,则将其设置为false
if(lastTouched <= 0){
    if(atLeastOneTouched){
        GameOverScreen(game,score,true); // game over complete
    }else{
        GameOverScreen(game,score,false); // game over failed
    }
}