Skip to content

Commit

Permalink
Added AnimationChain.GetTimeAtFrameIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Dec 1, 2023
1 parent 0a05d34 commit 82c9441
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ bin/
storage.ide

# AnimationEditor doesn't build in TeamCity, so let's add this in:
!/FRBDK/AnimationEditor/PreviewProject/bin/
!/FRBDK/AnimationEditor/PreviewProject/bin/
FRBDK/AnimationEditor/PreviewProject/bin/Debug/AESettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
namespace FlatRedBall.Content.AnimationChain
{
[XmlRoot("AnimationChain")]
#if !UWP
[Serializable]
#endif
public class AnimationChainSave
{
#region Fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,12 @@ public AnimationChain Clone()
return animationChain;
}

#region XML Docs
/// <summary>
/// Searches for and returns the AnimationFrame with its Name matching
/// the nameToSearchFor argument, or null if none are found.
/// </summary>
/// <param name="nameToSearchFor">The name of the AnimationFrame to search for.</param>
/// <returns>The AnimationFrame with matching name, or null if none exists.</returns>
#endregion
public AnimationFrame FindByName(string nameToSearchFor)
{
for (int i = 0; i < this.Count; i++)
Expand All @@ -172,15 +170,13 @@ public AnimationFrame FindByName(string nameToSearchFor)
return null;
}

#region XML Docs
/// <summary>
/// Returns the shortest absolute number of frames between the two argument frame numbers. This
/// method moves forward and backward and considers looping.
/// </summary>
/// <param name="frame1">The index of the first frame.</param>
/// <param name="frame2">The index of the second frame.</param>
/// <returns>The positive or negative number of frames between the two arguments.</returns>
#endregion
public int FrameToFrame(int frame1, int frame2)
{
int difference = frame2 - frame1;
Expand All @@ -193,7 +189,6 @@ public int FrameToFrame(int frame1, int frame2)
return difference;
}


public void ReplaceTexture(Texture2D oldTexture, Texture2D newTexture)
{
for (int i = 0; i < this.Count; i++)
Expand All @@ -211,9 +206,19 @@ public override string ToString()
return Name + " (" + Count + ")";
}

#endregion
public double GetTimeAtFrameIndex(int frameIndex)
{
var timeAtStartOfCurrentFrame = 0.0;
for (int i = 0; i < frameIndex; i++)
{
timeAtStartOfCurrentFrame += this[i].FrameLength;
}
return timeAtStartOfCurrentFrame;
}

#endregion

#endregion
#endregion

#region IEquatable<AnimationChain> Members

Expand Down
11 changes: 6 additions & 5 deletions Engines/FlatRedBallXNA/FlatRedBall/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ public float TextureScale
}


#region XML Docs
/// <summary>
/// Whether to flip the Sprite's texture on the y Axis (left and right switch).
/// </summary>
Expand All @@ -543,14 +542,12 @@ public float TextureScale
/// is no efficiency consequence for using either method. If a Sprite
/// is animated, this value will be overwritten by the AnimationChain being used.
/// </remarks>
#endregion
public bool FlipHorizontal
{
get { return mFlipHorizontal; }
set { mFlipHorizontal = value; }
}

#region XML Docs
/// <summary>
/// Whether to flip the Sprite's texture on the x Axis (top and bottom switch).
/// </summary>
Expand All @@ -561,7 +558,6 @@ public bool FlipHorizontal
/// There is no efficiency consequence for using either method. If a Sprite
/// is animated, this value will be overwritten by the AnimationChain being used.
/// </remarks>
#endregion
public bool FlipVertical
{
get { return mFlipVertical; }
Expand Down Expand Up @@ -1804,6 +1800,11 @@ public async Task PlayAnimationsAsync(params string[] animations)
foreach(var animation in animations)
{
CurrentChainName = animation;

if(CurrentChain == null)
{
throw new InvalidOperationException($"Could not set the current chain to {animation} because this animation does not exist");
}
// This should not try/catch. If it does, then any caller will continue after it's finished, causing additional logic to run after a screen has ended:
//try
//{
Expand Down Expand Up @@ -2011,7 +2012,6 @@ void UpdateFrameBasedOffOfTimeIntoAnimation()

if (timeIntoAnimation < frameTime)
{
mCurrentFrameIndex = frameIndex;

break;
}
Expand All @@ -2022,6 +2022,7 @@ void UpdateFrameBasedOffOfTimeIntoAnimation()
frameIndex = (frameIndex + 1) % CurrentChain.Count;
}
}
mCurrentFrameIndex = frameIndex;
}
}

Expand Down

0 comments on commit 82c9441

Please sign in to comment.