1
大家好我一直在關注這個教程這裏http://www.gogo-robot.com/2011/05/30/xna-skinned-model-animations/,到目前爲止,它的偉大了打動畫和一切,但現在我想將其展開,並停止連續環說,比如我按一個鍵當我釋放一把鑰匙時讓模型跳躍,我希望他停止跳躍,但如果我持有一把鑰匙,我希望他繼續跳躍。在這裏,我已經嘗試到目前爲止 並沒有任何工作。 我在這裏難倒如何做到這一點感謝任何幫助。XNA 4.0動畫循環
private void HandleInput(GameTime gameTime)
{
currentGamePadState = GamePad.GetState(PlayerIndex.One);
// Check for changing anims
//SkinningData skinningData = model.Tag as SkinningData;
SkinningData sd = jumper.model.Tag as SkinningData;
if (currentGamePadState.Buttons.A == ButtonState.Pressed)
{
if (jumper.animationPlayer.CurrentClip.Name != "Fire")
jumper.animationPlayer.StartClip(sd.AnimationClips["Fire"]);
}
if (currentGamePadState.Buttons.X == ButtonState.Pressed)
{
if (jumper.animationPlayer.CurrentClip.Name != "DieF")
jumper.animationPlayer.StartClip(sd.AnimationClips["DieF"]);
}
//does not work
if (currentGamePadState.Buttons.X == ButtonState.Released)
{
if (jumper.animationPlayer.CurrentClip.Name == "DieF")
jumper.animationPlayer.StartClip(sd.AnimationClips["Idel"]);
}
if (currentGamePadState.Buttons.Y == ButtonState.Pressed)
{
if (jumper.animationPlayer.CurrentClip.Name != "Idel")
jumper.animationPlayer.StartClip(sd.AnimationClips["Idle"]);
}
//does not work
if (jumper.animationPlayer.CurrentTime == jumper.animationPlayer.CurrentClip.Duration)
{
//set him back to idel
jumper.animationPlayer.StartClip(sd.AnimationClips["Idle"]);
}
我都試過,沒有運氣這些配置在遊戲
// Starts playing the entirety of the given clip
public void StartClip(string clip, bool loop)
{
AnimationClip clipVal = skinningData.AnimationClips[clip];
StartClip(clip, TimeSpan.FromSeconds(0), clipVal.Duration, loop);
}
// Plays a specific portion of the given clip, from one frame
// index to another
public void StartClip(string clip, int startFrame, int endFrame, bool loop)
{
AnimationClip clipVal = skinningData.AnimationClips[clip];
StartClip(clip, clipVal.Keyframes[startFrame].Time,
clipVal.Keyframes[endFrame].Time, loop);
}
// Plays a specific portion of the given clip, from one time
// to another
public void StartClip(string clip, TimeSpan StartTime, TimeSpan EndTime, bool loop)
{
CurrentClip = skinningData.AnimationClips[clip];
currentTime = TimeSpan.FromSeconds(0);
currentKeyframe = 0;
Done = false;
this.startTime = StartTime;
this.endTime = EndTime;
this.loop = loop;
// Copy the bind pose to the bone transforms array to reset the animation
skinningData.BindPose.CopyTo(BoneTransforms, 0);
}
你會在哪裏放環或主動變在遊戲中我真的不知道我這樣做的AnimationClip類中的迴路控制,但沒有工作,因爲之前有同樣的效果,但它僅打了一或兩幀那麼動畫frezes – MNM 2012-07-31 18:59:39
以快速瞭解您發佈的鏈接,發現這一點: '//如果我們達到了目的,循環回到開始。 bool hasLooped = false; (time> = currentClipValue.Duration) { hasLooped = true; time - = currentClipValue.Duration; } //如果我們循環,重新處理事件 如果(hasLooped) { CheckEvents(REF時,REF lastTime); } }' 它在你的animationPlayer – Clockworks 2012-07-31 21:31:06
的updateBoneTransforms功能是的,我注意到了,但沒有什麼用它做的foggiest。我試着只是評論這一點,這也是這個//如果我們達到了最後,循環回到開始。 bool hasLooped = false; (time> = currentClipValue.Duration) { hasLooped = false; // hasLooped = true; time - = currentClipValue.Duration; } 和動畫仍然環 – MNM 2012-08-01 12:44:11