Skip to content

Commit

Permalink
Added Sprite.UpdateToAnimationFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Dec 30, 2023
1 parent c48cdd6 commit d5796c7
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions Engines/FlatRedBallXNA/FlatRedBall/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ public override void ForceUpdateDependenciesDeep()
/// - Flip Horizontal (if IgnoreAnimationChainTextureFlip is true)
/// - Relative X and Y (if UseAnimationRelativePosition is true
/// - Executes AnimationFrame instructions
/// - Adjusts the size of the sprite if its TextureScale
/// - Adjusts the size of the sprite if its TextureScale is greater than 0
/// </summary>
/// <remarks>
/// This method is automatically called for sprites which are automatically updated (default) and which are using
Expand All @@ -1580,42 +1580,47 @@ public void UpdateToCurrentAnimationFrame()
mCurrentFrameIndex < mAnimationChains[mCurrentChainIndex].Count)
{
var frame = mAnimationChains[mCurrentChainIndex][mCurrentFrameIndex];
// Set the property so that any necessary values change:
// mTexture = mAnimationChains[mCurrentChainIndex][mCurrentFrameIndex].Texture;
Texture = frame.Texture;
this.Vertices[0].TextureCoordinate.X = frame.LeftCoordinate;
this.Vertices[1].TextureCoordinate.X = frame.RightCoordinate;
this.Vertices[2].TextureCoordinate.X = frame.RightCoordinate;
this.Vertices[3].TextureCoordinate.X = frame.LeftCoordinate;

this.Vertices[0].TextureCoordinate.Y = frame.TopCoordinate;
this.Vertices[1].TextureCoordinate.Y = frame.TopCoordinate;
this.Vertices[2].TextureCoordinate.Y = frame.BottomCoordinate;
this.Vertices[3].TextureCoordinate.Y = frame.BottomCoordinate;

if (mIgnoreAnimationChainTextureFlip == false)
{
mFlipHorizontal = frame.FlipHorizontal;
mFlipVertical = frame.FlipVertical;
}
UpdateToAnimationFrame(frame);

if (mUseAnimationRelativePosition)
{
RelativePosition.X = frame.RelativeX;
RelativePosition.Y = frame.RelativeY;
}
}
}

foreach(var instruction in frame.Instructions)
{
instruction.Execute();
}
public void UpdateToAnimationFrame(AnimationFrame frame)
{
// Set the property so that any necessary values change:
// mTexture = mAnimationChains[mCurrentChainIndex][mCurrentFrameIndex].Texture;
this.Texture = frame.Texture;
this.Vertices[0].TextureCoordinate.X = frame.LeftCoordinate;
this.Vertices[1].TextureCoordinate.X = frame.RightCoordinate;
this.Vertices[2].TextureCoordinate.X = frame.RightCoordinate;
this.Vertices[3].TextureCoordinate.X = frame.LeftCoordinate;

UpdateScale();

this.Vertices[0].TextureCoordinate.Y = frame.TopCoordinate;
this.Vertices[1].TextureCoordinate.Y = frame.TopCoordinate;
this.Vertices[2].TextureCoordinate.Y = frame.BottomCoordinate;
this.Vertices[3].TextureCoordinate.Y = frame.BottomCoordinate;

if (mIgnoreAnimationChainTextureFlip == false)
{
mFlipHorizontal = frame.FlipHorizontal;
mFlipVertical = frame.FlipVertical;
}

if (mUseAnimationRelativePosition)
{
RelativePosition.X = frame.RelativeX;
RelativePosition.Y = frame.RelativeY;
}

foreach (var instruction in frame.Instructions)
{
instruction.Execute();
}

UpdateScale();
}


#region XML Docs
/// <summary>
/// Returns a clone of this instance.
Expand Down

0 comments on commit d5796c7

Please sign in to comment.