Animation System Implemented
System is prepared to read its animations from an AnimationSet object now.
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MonoGame.Extended.TextureAtlases;
|
||||
|
||||
namespace QURO.AnimationLibrary
|
||||
{
|
||||
public class AnimatedSprite
|
||||
{
|
||||
public TextureAtlas CurrentTextureAtlas { get; set; }
|
||||
public Texture2D SpriteSheet { get; set; }
|
||||
private Animation currentAnimation;
|
||||
public Animation CurrentAnimation
|
||||
{
|
||||
@@ -18,15 +17,15 @@ namespace QURO.AnimationLibrary
|
||||
}
|
||||
}
|
||||
public int CurrentFrameIndex { get; set; }
|
||||
public TextureRegion2D CurrentFrame => CurrentAnimation.Frames[CurrentFrameIndex];
|
||||
public Rectangle CurrentFrame => CurrentAnimation.Frames[CurrentFrameIndex];
|
||||
|
||||
private float timer;
|
||||
|
||||
public AnimatedSprite() { }
|
||||
|
||||
public AnimatedSprite(TextureAtlas textureAtlas, Animation startingAnimation)
|
||||
public AnimatedSprite(Texture2D spriteSheet, Animation startingAnimation)
|
||||
{
|
||||
CurrentTextureAtlas = textureAtlas;
|
||||
SpriteSheet = spriteSheet;
|
||||
CurrentAnimation = startingAnimation;
|
||||
timer = CurrentAnimation.Delay;
|
||||
}
|
||||
@@ -65,15 +64,15 @@ namespace QURO.AnimationLibrary
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 position, Color tint)
|
||||
{
|
||||
spriteBatch.Draw(CurrentTextureAtlas.Texture, position, CurrentFrame.Bounds, tint);
|
||||
spriteBatch.Draw(SpriteSheet, position, CurrentFrame, tint);
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 position, Vector2 spriteOffset, Color tint)
|
||||
{
|
||||
Rectangle sourceRect = CurrentFrame.Bounds;
|
||||
Rectangle sourceRect = CurrentFrame;
|
||||
sourceRect.Offset(spriteOffset);
|
||||
|
||||
spriteBatch.Draw(CurrentTextureAtlas.Texture, position, sourceRect, tint);
|
||||
spriteBatch.Draw(SpriteSheet, position, sourceRect, tint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MonoGame.Extended.TextureAtlases;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace QURO.AnimationLibrary
|
||||
{
|
||||
@@ -8,24 +8,10 @@ namespace QURO.AnimationLibrary
|
||||
public bool IsLooping { get; set; }
|
||||
public float Delay { get; set; }
|
||||
|
||||
public TextureRegion2D[] Frames { get; set; }
|
||||
public Rectangle[] Frames { get; set; }
|
||||
|
||||
public bool IsStillImage => Frames.Length <= 1;
|
||||
|
||||
public Animation() { }
|
||||
|
||||
public Animation(string name, TextureAtlas textureAtlas, string[] frameNames, float delaySetting = 0.2f, bool willLoop = false)
|
||||
{
|
||||
Name = name;
|
||||
|
||||
Frames = new TextureRegion2D[frameNames.Length];
|
||||
|
||||
for (int index = 0; index < frameNames.Length; index++)
|
||||
{
|
||||
Frames[index] = textureAtlas.GetRegion(frameNames[index]);
|
||||
}
|
||||
IsLooping = willLoop;
|
||||
Delay = delaySetting;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QURO.AnimationLibrary
|
||||
{
|
||||
public class AnimationSet
|
||||
{
|
||||
public Dictionary<string, Animation> Anims;
|
||||
}
|
||||
}
|
||||
+1
-9
@@ -31,16 +31,10 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MonoGame.Extended, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MonoGame.Extended.1.1.0\lib\portable-net45+win8+wpa81\MonoGame.Extended.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MonoGame.Framework, Version=3.8.0.76, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>C:\Program Files (x86)\MonoGame\v3.0\Assemblies\DesktopGL\MonoGame.Framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@@ -53,10 +47,8 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AnimatedSprite.cs" />
|
||||
<Compile Include="Animation.cs" />
|
||||
<Compile Include="AnimationSet.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MonoGame.Extended" version="1.1.0" targetFramework="net461" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user