これは、状態を切り替えるためのコードです。
if (mCurrentState == State.Walking)
{
action = "stand";
Update_Stand(gameTime);
if (aCurrentKeyboardState.IsKeyDown(Keys.Left) == true)
{
action = "run";
feetPosition.X += MOVE_LEFT;
effect = SpriteEffects.None;
Update_Run(gameTime);
}
else if (aCurrentKeyboardState.IsKeyDown(Keys.Right) == true)
{
action = "run";
feetPosition.X += MOVE_RIGHT;
effect = SpriteEffects.FlipHorizontally;
Update_Run(gameTime);
}
if (aCurrentKeyboardState.IsKeyDown(Keys.Z) == true)
{
mCurrentState = State.Hitting;
}
}
if (mCurrentState == State.Hitting)
{
action = "hit";
Update_Hit(gameTime);
mCurrentState = State.Walking;
}
私の Update_Hit(GameTime gameTime) メソッドはそのようなものです。アニメーション化するスプライトが 2 つあります。
public void Update_Hit(GameTime gameTime)
{
// Check if it is a time to progress to the next frame
if (nextFrame_Hit >= frameInterval_Hit)
{
// Progress to the next frame in the row
currentFrame_Hit.X++;
// If reached end of the row advance to the next row, reset to the first frame
if (currentFrame_Hit.X >= sheetSize_Hit.X)
{
currentFrame_Hit.X = 0;
currentFrame_Hit.Y++;
}
// If reached last row in the frame sheet, jump to the first row again
if (currentFrame_Hit.Y >= sheetSize_Hit.Y)
currentFrame_Hit.Y = 0;
// Reset time interval for next frame
nextFrame_Hit = TimeSpan.Zero;
}
else
{
// Wait for the next frame
nextFrame_Hit += gameTime.ElapsedGameTime;
}
}
状態を歩行に戻す前にヒット アニメーションを完了するにはどうすればよいですか?