嗯,这很难解释,所以我会尽我最大的努力…
我有这个方法:
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变量设置为角色的站立帧。
我一直在想什么时候重置这个变量,但我不知道:/
发布于 2011-07-09 03:46:55
您需要保留另一个变量"previousDirection",该变量是在方法的末尾设置的。当您进入该方法时,请检查方向是否发生了变化,并相应地设置lastFrameChange和currentFrame。
https://stackoverflow.com/questions/6629602
复制相似问题