gpt4 book ai didi

java - 设置变量一次

转载 作者:行者123 更新时间:2023-12-02 08:14:53 25 4
gpt4 key购买 nike

嗯,很难解释,所以我会尽力...

我有这个方法:

private void manageActions(long delta) {
lastFrameChange += delta;

if(currentAction == States.Action.STANDING) {
lastFrameChange = 0;
resetDirections();
}

if(currentAction == States.Action.WALKING) {
switch(currentDirection) {
case UP:
if(lastFrameChange > 75.0f) {
lastFrameChange = 0;
if(++currentFrame > 2)
currentFrame = 1;
}
break;
case DOWN:
if(lastFrameChange > 75.0f) {
lastFrameChange = 0;
if(++currentFrame > 5)
currentFrame = 4;
}
break;
case LEFT:
if(lastFrameChange > 75.0f) {
lastFrameChange = 0;
if(++currentFrame > 7)
currentFrame = 6;
}
break;
case RIGHT:
if(lastFrameChange > 75.0f) {
lastFrameChange = 0;
if(++currentFrame > 9)
currentFrame = 8;
}
break;
}
}
}

这是一种根据角色的方向和状态(站立、行走...)更改角色框架的方法,问题是当我的角色向上然后向右移动时,它会穿过它们之间的所有框架。这是因为每次您以正确的方向更改方向时,currentFrame 变量都不会重置,并且会保留最后一帧。

还有一件事,resetDirections() 将 currentFrame 变量设置为角色的站立框架。

我一直在考虑何时重置此变量,但我不知道:/

最佳答案

您需要保留另一个变量“previousDirection”,该变量在方法末尾设置。当您进入该方法时,检查是否有方向变化并相应地设置lastFrameChange和currentFrame。

关于java - 设置变量一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6629602/

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