Simplify and fix animation glitches.

This commit is contained in:
Paul Chote
2015-04-25 21:53:31 +12:00
committed by Matthias Mailänder
parent 75624560d2
commit 8f93d7b5d7
8 changed files with 33 additions and 35 deletions

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Graphics
this.facingFunc = facingFunc;
}
int CurrentFrame { get { return backwards ? CurrentSequence.Start + CurrentSequence.Length - frame - 1 : frame; } }
public int CurrentFrame { get { return backwards ? CurrentSequence.Start + CurrentSequence.Length - frame - 1 : frame; } }
public Sprite Image { get { return CurrentSequence.GetSprite(CurrentFrame, facingFunc()); } }
public IEnumerable<IRenderable> Render(WPos pos, WVec offset, int zOffset, PaletteReference palette, float scale)
@@ -139,6 +139,24 @@ namespace OpenRA.Graphics
tickFunc = () => frame = func();
}
public void PlayFetchDirection(string sequenceName, Func<int> direction)
{
tickAlways = false;
CurrentSequence = sequenceProvider.GetSequence(name, sequenceName);
timeUntilNextFrame = CurrentSequence != null ? CurrentSequence.Tick : defaultTick;
frame = 0;
tickFunc = () =>
{
var d = direction();
if (d > 0 && ++frame >= CurrentSequence.Length)
frame = 0;
if (d < 0 && --frame < 0)
frame = CurrentSequence.Length - 1;
};
}
int timeUntilNextFrame;
Action tickFunc;