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;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MonoGame.Extended.TextureAtlases;
|
|
||||||
|
|
||||||
namespace QURO.AnimationLibrary
|
namespace QURO.AnimationLibrary
|
||||||
{
|
{
|
||||||
public class AnimatedSprite
|
public class AnimatedSprite
|
||||||
{
|
{
|
||||||
public TextureAtlas CurrentTextureAtlas { get; set; }
|
public Texture2D SpriteSheet { get; set; }
|
||||||
private Animation currentAnimation;
|
private Animation currentAnimation;
|
||||||
public Animation CurrentAnimation
|
public Animation CurrentAnimation
|
||||||
{
|
{
|
||||||
@@ -18,15 +17,15 @@ namespace QURO.AnimationLibrary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int CurrentFrameIndex { get; set; }
|
public int CurrentFrameIndex { get; set; }
|
||||||
public TextureRegion2D CurrentFrame => CurrentAnimation.Frames[CurrentFrameIndex];
|
public Rectangle CurrentFrame => CurrentAnimation.Frames[CurrentFrameIndex];
|
||||||
|
|
||||||
private float timer;
|
private float timer;
|
||||||
|
|
||||||
public AnimatedSprite() { }
|
public AnimatedSprite() { }
|
||||||
|
|
||||||
public AnimatedSprite(TextureAtlas textureAtlas, Animation startingAnimation)
|
public AnimatedSprite(Texture2D spriteSheet, Animation startingAnimation)
|
||||||
{
|
{
|
||||||
CurrentTextureAtlas = textureAtlas;
|
SpriteSheet = spriteSheet;
|
||||||
CurrentAnimation = startingAnimation;
|
CurrentAnimation = startingAnimation;
|
||||||
timer = CurrentAnimation.Delay;
|
timer = CurrentAnimation.Delay;
|
||||||
}
|
}
|
||||||
@@ -65,15 +64,15 @@ namespace QURO.AnimationLibrary
|
|||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch, Vector2 position, Color tint)
|
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)
|
public void Draw(SpriteBatch spriteBatch, Vector2 position, Vector2 spriteOffset, Color tint)
|
||||||
{
|
{
|
||||||
Rectangle sourceRect = CurrentFrame.Bounds;
|
Rectangle sourceRect = CurrentFrame;
|
||||||
sourceRect.Offset(spriteOffset);
|
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
|
namespace QURO.AnimationLibrary
|
||||||
{
|
{
|
||||||
@@ -8,24 +8,10 @@ namespace QURO.AnimationLibrary
|
|||||||
public bool IsLooping { get; set; }
|
public bool IsLooping { get; set; }
|
||||||
public float Delay { get; set; }
|
public float Delay { get; set; }
|
||||||
|
|
||||||
public TextureRegion2D[] Frames { get; set; }
|
public Rectangle[] Frames { get; set; }
|
||||||
|
|
||||||
public bool IsStillImage => Frames.Length <= 1;
|
public bool IsStillImage => Frames.Length <= 1;
|
||||||
|
|
||||||
public Animation() { }
|
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>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<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">
|
<Reference Include="MonoGame.Framework, Version=3.8.0.76, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>C:\Program Files (x86)\MonoGame\v3.0\Assemblies\DesktopGL\MonoGame.Framework.dll</HintPath>
|
<HintPath>C:\Program Files (x86)\MonoGame\v3.0\Assemblies\DesktopGL\MonoGame.Framework.dll</HintPath>
|
||||||
</Reference>
|
</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" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
@@ -53,10 +47,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AnimatedSprite.cs" />
|
<Compile Include="AnimatedSprite.cs" />
|
||||||
<Compile Include="Animation.cs" />
|
<Compile Include="Animation.cs" />
|
||||||
|
<Compile Include="AnimationSet.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<None Include="packages.config" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</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>
|
|
||||||
+1
-1
@@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.27703.2047
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuzzSwap", "PuzzSwap\PuzzSwap.csproj", "{CD753795-0CB4-4F05-A0E7-2D2EFC968D82}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuzzSwap", "PuzzSwap\PuzzSwap.csproj", "{CD753795-0CB4-4F05-A0E7-2D2EFC968D82}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimationLibrary", "AnimationLibrary\AnimationLibrary.csproj", "{69DADC27-FBEB-4625-9212-6EB5BED5102A}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QURO.AnimationLibrary", "AnimationLibrary\QURO.AnimationLibrary.csproj", "{69DADC27-FBEB-4625-9212-6EB5BED5102A}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|||||||
Reference in New Issue
Block a user