gpt4 book ai didi

java - libGDX actor 在运动时不会表现得正确

转载 作者:行者123 更新时间:2023-12-01 12:25:38 26 4
gpt4 key购买 nike

我试图让 Actor 每 X 秒随机移动一次。 act的代码是这样的:

@Override
public void act(float delta)
{
super.act(delta);

if (delta > (float)(rand.nextInt(5)+3))
{
switch(rand.nextInt(3))
{
case 0:
moveBy(3,0);
break;
case 1:
moveBy(-3,0);
break;
case 2:
moveBy(0,3);
break;
case 3:
moveBy(0,-3);
break;
}
}

}

调试仅显示 X 增加的超时时间,并在 ~103 处停止。问题可能是什么?Random 在构造函数中使用 System.currentTimeMillis() 种子进行初始化。

最佳答案

您好,抱歉我的英语测试是这个简单的示例,如果您愿意,请更改最终变量进行调整。

private Random random= new Random();

private float inttt = 0;

private float tiempo = 0;

private int randomT = 0;

private int randomN = 0;

private final int MAXTIEMPO = 15; // cambiar para aumentar o disminuir el tiempo que pasa como maximo entre un movimiento y otro.//changed to increase or decrease the time spent at most from one movement to another.

public int RandomNumber(float delta){

tiempo += delta;

if(randomT == 0 || randomN == 0){

random.setSeed(System.nanoTime() * (long)inttt);
this.randomN = random.nextInt(MAXTIEMPO);
inttt += randomN;
randomT = randomN;

Gdx.app.log("randomN", ""+randomN);
Gdx.app.log("randomT", ""+randomT);
Gdx.app.log("tiempo", ""+tiempo);

return 0;

}else if(randomT != 0 && tiempo >= randomT){

tiempo = 0;
randomT = 0;

Gdx.app.log("randomN", ""+randomN);
Gdx.app.log("randomT", ""+randomT);
Gdx.app.log("tiempo", ""+tiempo);

return randomN;

}else{

Gdx.app.log("randomN", ""+randomN);
Gdx.app.log("randomT", ""+randomT);
Gdx.app.log("tiempo", ""+tiempo);

return 0;
}
}

@覆盖公共(public)无效行为( float 增量){ super.act(delta);

    if (RandomNumber(delta) != 0){

switch(rand.nextInt(4)){

case 0:
moveBy(3,0);
break;
case 1:
moveBy(-3,0);
break;
case 2:
moveBy(0,3);
break;
case 3:
moveBy(0,-3);
break;
}
}

关于java - libGDX actor 在运动时不会表现得正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26361252/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com