Implementation Working
Used AnimationGenerator to port old animations into new system, tested and seems stable.
This commit is contained in:
@@ -17,7 +17,7 @@ namespace QURO.AnimationLibrary
|
||||
}
|
||||
}
|
||||
public int CurrentFrameIndex { get; set; }
|
||||
public Rectangle CurrentFrame => CurrentAnimation.Frames[CurrentFrameIndex];
|
||||
public Frame CurrentFrame => CurrentAnimation.Frames[CurrentFrameIndex];
|
||||
|
||||
private float timer;
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace QURO.AnimationLibrary
|
||||
{
|
||||
SpriteSheet = spriteSheet;
|
||||
CurrentAnimation = startingAnimation;
|
||||
timer = CurrentAnimation.Delay;
|
||||
timer = CurrentFrame.Delay;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
CurrentFrameIndex = 0;
|
||||
timer = CurrentAnimation.Delay;
|
||||
timer = CurrentFrame.Delay;
|
||||
}
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
@@ -53,7 +53,7 @@ namespace QURO.AnimationLibrary
|
||||
CurrentFrameIndex = 0;
|
||||
}
|
||||
}
|
||||
timer = CurrentAnimation.Delay;
|
||||
timer = CurrentFrame.Delay;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -64,12 +64,12 @@ namespace QURO.AnimationLibrary
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 position, Color tint)
|
||||
{
|
||||
spriteBatch.Draw(SpriteSheet, position, CurrentFrame, tint);
|
||||
spriteBatch.Draw(SpriteSheet, position, CurrentFrame.SourceRect, tint);
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 position, Vector2 spriteOffset, Color tint)
|
||||
{
|
||||
Rectangle sourceRect = CurrentFrame;
|
||||
Rectangle sourceRect = CurrentFrame.SourceRect;
|
||||
sourceRect.Offset(spriteOffset);
|
||||
|
||||
spriteBatch.Draw(SpriteSheet, position, sourceRect, tint);
|
||||
|
||||
@@ -6,12 +6,31 @@ namespace QURO.AnimationLibrary
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public bool IsLooping { get; set; }
|
||||
public float Delay { get; set; }
|
||||
|
||||
public Rectangle[] Frames { get; set; }
|
||||
public Frame[] Frames { get; set; }
|
||||
|
||||
public bool IsStillImage => Frames.Length <= 1;
|
||||
|
||||
public Animation() { }
|
||||
|
||||
public Animation(string name, Frame[] frames, bool loop)
|
||||
{
|
||||
Name = name;
|
||||
Frames = frames;
|
||||
IsLooping = loop;
|
||||
}
|
||||
|
||||
public Animation(string name, Rectangle[] sourceRects, float delay, bool loop)
|
||||
{
|
||||
Name = name;
|
||||
|
||||
Frames = new Frame[sourceRects.Length];
|
||||
for(int index = 0; index < sourceRects.Length; index++)
|
||||
{
|
||||
Frames[index] = new Frame(sourceRects[index], delay);
|
||||
}
|
||||
|
||||
IsLooping = loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,25 @@ namespace QURO.AnimationLibrary
|
||||
public class AnimationSet
|
||||
{
|
||||
public Dictionary<string, Animation> Anims;
|
||||
|
||||
public AnimationSet()
|
||||
{
|
||||
Anims = new Dictionary<string, Animation>();
|
||||
}
|
||||
|
||||
public void Add(Animation anim)
|
||||
{
|
||||
Anims.Add(anim.Name, anim);
|
||||
}
|
||||
|
||||
public void Remove(Animation anim)
|
||||
{
|
||||
Anims.Remove(anim.Name);
|
||||
}
|
||||
|
||||
public void Remove(string animName)
|
||||
{
|
||||
Anims.Remove(animName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace QURO.AnimationLibrary
|
||||
{
|
||||
public class Frame
|
||||
{
|
||||
public Rectangle SourceRect { get; set; }
|
||||
public float Delay { get; set; }
|
||||
|
||||
public Frame() { }
|
||||
|
||||
public Frame(Rectangle sourceRectangle, float delay)
|
||||
{
|
||||
SourceRect = sourceRectangle;
|
||||
Delay = delay;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@
|
||||
<ProjectGuid>{69DADC27-FBEB-4625-9212-6EB5BED5102A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>AnimationLibrary</RootNamespace>
|
||||
<AssemblyName>AnimationLibrary</AssemblyName>
|
||||
<RootNamespace>QURO.AnimationLibrary</RootNamespace>
|
||||
<AssemblyName>QURO.AnimationLibrary</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
@@ -48,6 +48,7 @@
|
||||
<Compile Include="AnimatedSprite.cs" />
|
||||
<Compile Include="Animation.cs" />
|
||||
<Compile Include="AnimationSet.cs" />
|
||||
<Compile Include="Frame.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
Reference in New Issue
Block a user