Skip to content

Commit

Permalink
Add colour to animator. Prepare for nuget release.
Browse files Browse the repository at this point in the history
  • Loading branch information
loodakrawa committed Oct 23, 2016
1 parent 0e468f0 commit 9f9fd42
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
10 changes: 6 additions & 4 deletions SpriterDotNet.MonoGame.Example/SpriterGameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class SpriterGameState : GameState
"W/A/S/D = Move",
"Q/E = Rotate",
"N/M = Scale",
"F/G = Flip"
"F/G = Flip",
"J = Toggle Colour"
};

private static readonly Config config = new Config
Expand Down Expand Up @@ -120,7 +121,7 @@ public override void Draw(GameTime gameTime)
public override void Update(GameTime gameTime)
{
stats.OnUpdate(gameTime);
Vector2 scale = currentAnimator.Scale;
Vector2 scale = currentAnimator.Scale;

if (IsPressed(Keys.Enter)) SwitchEntity();
if (IsPressed(Keys.Space)) currentAnimator.Play(GetNextAnimation());
Expand All @@ -131,15 +132,16 @@ public override void Update(GameTime gameTime)
if (IsPressed(Keys.T)) currentAnimator.Transition(GetNextAnimation(), 1000.0f);
if (IsPressed(Keys.C)) PushCharacterMap();
if (IsPressed(Keys.V)) currentAnimator.SpriteProvider.PopCharMap();
if (IsPressed(Keys.J)) currentAnimator.Color = currentAnimator.Color == Color.White ? Color.Red : Color.White;

if (IsPressed(Keys.W)) currentAnimator.Position += new Vector2(0, -10);
if (IsPressed(Keys.S)) currentAnimator.Position += new Vector2(0, 10);
if (IsPressed(Keys.A)) currentAnimator.Position += new Vector2(-10, 0);
if (IsPressed(Keys.D)) currentAnimator.Position += new Vector2(10, 0);
if (IsPressed(Keys.Q)) currentAnimator.Rotation -= 15 * (float)Math.PI / 180;
if (IsPressed(Keys.E)) currentAnimator.Rotation += 15 * (float)Math.PI / 180;
if (IsPressed(Keys.N)) currentAnimator.Scale -= new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
if (IsPressed(Keys.M)) currentAnimator.Scale += new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
if (IsPressed(Keys.N)) currentAnimator.Scale -= new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
if (IsPressed(Keys.M)) currentAnimator.Scale += new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
if (IsPressed(Keys.F)) currentAnimator.Scale *= new Vector2(-1, 1);
if (IsPressed(Keys.G)) currentAnimator.Scale *= new Vector2(1, -1);

Expand Down
23 changes: 11 additions & 12 deletions SpriterDotNet.MonoGame/MonoGameAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MonoGameAnimator : Animator<Sprite, SoundEffect>
/// <summary>
/// Scale factor of the animator. Negative values flip the image.
/// </summary>
public virtual Vector2 Scale { get; set; }
public virtual Vector2 Scale { get; set; } = Vector2.One;

/// <summary>
/// Rotation in radians.
Expand All @@ -34,15 +34,20 @@ public class MonoGameAnimator : Animator<Sprite, SoundEffect>
/// <summary>
/// The drawing depth. Should be in the [0,1] interval.
/// </summary>
public virtual float Depth { get; set; }
public virtual float Depth { get; set; } = DefaultDepth;

/// <summary>
/// The depth distance between different sprites of the same animation.
/// </summary>
public virtual float DeltaDepth { get; set; }
public virtual float DeltaDepth { get; set; } = DefaultDeltaDepth;

protected Stack<DrawInfo> DrawInfoPool { get; set; }
protected List<DrawInfo> DrawInfos { get; set; }
/// <summary>
/// The color used to render all the sprites.
/// </summary>
public virtual Color Color { get; set; } = Color.White;

protected Stack<DrawInfo> DrawInfoPool { get; set; } = new Stack<DrawInfo>();
protected List<DrawInfo> DrawInfos { get; set; } = new List<DrawInfo>();
protected Matrix Transform { get; set; }

private static readonly float SpriteAtlasRotation = -90 * MathHelper.DegToRad;
Expand All @@ -51,12 +56,6 @@ public class MonoGameAnimator : Animator<Sprite, SoundEffect>

public MonoGameAnimator(SpriterEntity entity, IProviderFactory<Sprite, SoundEffect> providerFactory = null) : base(entity, providerFactory)
{
DrawInfoPool = new Stack<DrawInfo>();
DrawInfos = new List<DrawInfo>();

Scale = Vector2.One;
DeltaDepth = DefaultDeltaDepth;
Depth = DefaultDepth;
}

/// <summary>
Expand Down Expand Up @@ -146,7 +145,7 @@ protected override void ApplySpriteTransform(Sprite sprite, SpriterObject info)
di.Origin = new Vector2(originX, originY);
di.Scale = scale;
di.Rotation = rotation + (sprite.Rotated ? SpriteAtlasRotation : 0);
di.Color = Color.White * info.Alpha;
di.Color = Color * info.Alpha;
di.Effects = effects;
di.Depth = depth;

Expand Down
9 changes: 8 additions & 1 deletion SpriterDotNet.MonoGame/Sprite.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using System;
// Copyright (c) 2015 The original author or authors
//
// This software may be modified and distributed under the terms
// of the zlib license. See the LICENSE file for details.

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace SpriterDotNet.MonoGame
{
/// <summary>
/// A wrapper around Texture2D to cater for sprite atlas metadata.
/// </summary>
public class Sprite
{
public Texture2D Texture { get; set; }
Expand Down
11 changes: 9 additions & 2 deletions SpriterDotNet.MonoGame/SpriterContentLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using System;
// Copyright (c) 2015 The original author or authors
//
// This software may be modified and distributed under the terms
// of the zlib license. See the LICENSE file for details.

using System;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Audio;
using System.IO;
Expand All @@ -11,10 +16,12 @@ namespace SpriterDotNet.MonoGame
{
public class SpriterContentLoader
{
public Spriter Spriter { get; private set; }

private readonly ContentManager content;
private readonly string scmlPath;
private readonly string rootPath;
public Spriter Spriter { get; private set; }

private Dictionary<int, SpriterAtlas> atlases;
private Dictionary<SpriterAtlas, Dictionary<string, ImageInfo>> infos;

Expand Down
2 changes: 1 addition & 1 deletion SpriterDotNet.MonoGame/SpriterDotNet.MonoGame.Debug.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<metadata>
<id>SpriterDotNet.MonoGame</id>
<version>1.5.1</version>
<version>$version$</version>
<authors>Luka "loodakrawa" Sverko</authors>
<owners>Luka "loodakrawa" Sverko</owners>
<licenseUrl>https://github.com/loodakrawa/SpriterDotNet/blob/develop/LICENSE</licenseUrl>
Expand Down
2 changes: 1 addition & 1 deletion SpriterDotNet.MonoGame/SpriterDotNet.MonoGame.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<metadata>
<id>SpriterDotNet.MonoGame</id>
<version>1.5.1</version>
<version>$version$</version>
<authors>Luka "loodakrawa" Sverko</authors>
<owners>Luka "loodakrawa" Sverko</owners>
<licenseUrl>https://github.com/loodakrawa/SpriterDotNet/blob/develop/LICENSE</licenseUrl>
Expand Down

0 comments on commit 9f9fd42

Please sign in to comment.