我正在做一个游戏,它有不统一的关键帧动画,这样就可以为了平衡的目的而改变启动,活动和恢复帧。我有循环动画,如闲置和步行,循环相当顺利,但攻击动画,只有发挥一次是非常口吃,有时发挥多次。
我已经尝试了以下计算没有帮助的伪ish代码
in animation class:
isAnimationFinished(float time)
return (time / animationLength) >= 0.95
// Note: 0.95 seemed like a good value as it seemed that the last frame in any animation
// would result in a value between 0.95 and 0.99 when used in this calculation.
// frameTimes is an array of floats that stores the amount of time, in milliseconds,
// that a key frame should be drawn for.
// One example of an array used is:
float[] jabFrames = {
FRAME * frameData[0].getStartUpFrames(), FRAME * frameData[0].getActiveFrames(),
FRAME * frameData[0].getRecoveryFrames()
};
// Where FRAME is a float of 1/60f and frameData is an int array
getAnimationDuration()
sum = 0.0
for each floatValue in frameTimes:
sum += floatValue
return sum
...
in the pawn class's draw function:
draw(deltaTime):
stateTime += deltaTime (time since last render)
get the animation based on the animation_state
if(animation_state is JAB and animation.isAnimationFinished(stateTime))
animation_state = IDLE
if(stateTime >= animation.getAnimationDuration())
stateTime -= animation.getAnimationDuration()
drawAnimation()
1条答案
按热度按时间mrphzbgm1#
如果使用libGDX中的Animation类,则可以使用以下方法(从API):
所以你只需要知道当前的
stateTime
,就像你在伪代码中已经做过的那样计算:有关如何使用libGDX动画的进一步介绍,请参阅this tutorial。
在我的一个项目中,我使用了一个 Package 器类来实现一些额外的功能。如果你想使用它,你可以在GitHub上找到它,或者使用它的当前版本:
AnimationDirector
AnimationSpriteConfig