从我所看到的代码,你张贴将只画你踢动画的最后一帧作为for循环在LoopOnce方法循环所有帧,只画最后一个。这是因为每次更新都会调用draw方法一次。
XNA首先调用update方法,然后调用draw。因此,在更新方法中,将动画的当前帧设置为“最大帧”(max frame),然后进入“绘制方法”(draw method),然后绘制当前帧,此时是最后一帧。
要使其工作,您只需为每次要更新的调用将要绘制的帧增加一个。
private void UpdateAttack(KeyboardState current, KeyboardState last, GameTime gameTime)
{
if (current.IsKeyDown(Keys.S) && last.IsKeyUp(Keys.S))
{
mCurrentState =State.Kicking;
currentImageIndex=25;
}
if(mCurrentState ==State.Kicking)
neutralStandingKick(gameTime);
}
private void neutralStandingKick(GameTime gameTime)
{
currentImageIndex++;
if(currentImageIndex==30) mCurrentStart = State.SomeOtherState;
}
删除“一次绘制”方法。您需要将State.SomeOtherState替换为对象未启动时所处的状态。您可能还想用常量交换硬编码的帧编号。不需要更改绘制方法,此动画才能工作。希望这有帮助。