2018-08-07 11:01:59 +08:00
using System.Xml.Serialization ;
2018-12-30 18:00:05 +08:00
using Microsoft.Xna.Framework ;
using Netcode ;
2017-09-12 09:35:31 +08:00
namespace StardustCore.Animations
{
2018-12-30 18:00:05 +08:00
/// <summary>A custom class used to deal with custom animations/</summary>
public class Animation
2017-09-12 09:35:31 +08:00
{
2018-12-30 18:00:05 +08:00
/// <summary>The source rectangle on the texture to display.</summary>
public Rectangle sourceRectangle ;
/// <summary>The duration of the frame in length.</summary>
public int frameDuration ;
/// <summary>The duration until the next frame.</summary>
public int frameCountUntilNextAnimation ;
2018-08-07 11:01:59 +08:00
2018-12-30 18:00:05 +08:00
[XmlIgnore]
public NetFields NetFields { get ; } = new NetFields ( ) ;
2017-09-12 09:35:31 +08:00
2018-12-10 17:33:10 +08:00
public Animation ( )
{
2018-12-30 18:00:05 +08:00
this . sourceRectangle = new Rectangle ( 0 , 0 , 16 , 16 ) ;
2018-12-16 03:49:56 +08:00
this . frameCountUntilNextAnimation = - 1 ;
2018-12-15 19:00:32 +08:00
this . frameDuration = - 1 ;
2018-12-10 17:33:10 +08:00
}
2018-03-06 12:46:45 +08:00
2019-07-18 01:18:51 +08:00
public Animation ( int xPos , int yPos , int width , int height )
{
this . sourceRectangle = new Rectangle ( xPos , yPos , width , height ) ;
this . frameCountUntilNextAnimation = - 1 ;
this . frameDuration = - 1 ;
}
public Animation ( int xPos , int yPos , int width , int height , int existsForXFrames )
{
this . sourceRectangle = new Rectangle ( xPos , yPos , width , height ) ;
this . frameDuration = existsForXFrames ;
}
2018-12-30 18:00:05 +08:00
/// <summary>Constructor that causes the animation frame count to be set to -1; This forces it to never change.</summary>
2018-03-06 12:46:45 +08:00
/// <param name="SourceRectangle">The draw source for this animation.</param>
public Animation ( Rectangle SourceRectangle )
{
2018-12-30 18:00:05 +08:00
this . sourceRectangle = SourceRectangle ;
2018-12-16 03:49:56 +08:00
this . frameCountUntilNextAnimation = - 1 ;
2018-12-30 18:00:05 +08:00
this . frameDuration = - 1 ;
2018-03-06 12:46:45 +08:00
}
2018-12-30 18:00:05 +08:00
/// <summary>Construct an instance.</summary>
2018-03-06 12:46:45 +08:00
/// <param name="SourceRectangle">The draw source for this animation.</param>
/// <param name="existForXFrames">How many on screen frames this animation stays for. Every draw frame decrements an active animation by 1 frame. Set this to -1 to have it be on the screen infinitely.</param>
2018-12-30 18:00:05 +08:00
public Animation ( Rectangle SourceRectangle , int existForXFrames )
2017-09-12 09:35:31 +08:00
{
2018-12-30 18:00:05 +08:00
this . sourceRectangle = SourceRectangle ;
this . frameDuration = existForXFrames ;
2017-09-12 09:35:31 +08:00
}
2018-12-30 18:00:05 +08:00
/// <summary>Decrements the amount of frames this animation is on the screen for by 1.</summary>
2017-09-12 09:35:31 +08:00
public void tickAnimationFrame ( )
{
2018-12-30 18:00:05 +08:00
this . frameCountUntilNextAnimation - - ;
2017-09-12 09:35:31 +08:00
}
2018-12-30 18:00:05 +08:00
/// <summary>This sets the animation frame count to be the max duration. I.E restart the timer.</summary>
2017-09-12 09:35:31 +08:00
public void startAnimation ( )
{
2018-12-30 18:00:05 +08:00
this . frameCountUntilNextAnimation = this . frameDuration ;
2017-09-12 09:35:31 +08:00
}
}
}