tweaked player animation again

This commit is contained in:
Dylan Wilson
2016-09-02 21:32:33 +10:00
parent fa9b9a8016
commit c8bd27df3d
2 changed files with 4 additions and 6 deletions
@@ -34,9 +34,6 @@ namespace Demo.Platformer.Entities
{
var texture = content.Load<Texture2D>("tiny-characters");
_characterTextureAtlas = TextureAtlas.Create(texture, 32, 32, 15);
var animationFactory = new SpriteSheetAnimationFactory(_characterTextureAtlas);
animationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0, 1, 2, 3 }, isReversed: true));
}
public Entity CreatePlayer(Vector2 position)
@@ -48,7 +45,7 @@ namespace Demo.Platformer.Entities
animationFactory.Add("walk", new SpriteSheetAnimationData(new[] { 0, 1, 2, 3 }));
animationFactory.Add("jump", new SpriteSheetAnimationData(new[] { 8, 9 }, isLooping: false));
entity.AttachComponent(new AnimatedSprite(animationFactory, "idle"));
entity.AttachComponent(new AnimatedSprite(animationFactory));
entity.AttachComponent(new BasicCollisionBody(textureRegion.Size, Vector2.One * 0.5f));
entity.AttachComponent(new PlayerCollisionHandler());
entity.AttachComponent(new PlayerState());
@@ -6,12 +6,13 @@ namespace MonoGame.Extended.Animations.SpriteSheets
{
public class AnimatedSprite : Sprite
{
public AnimatedSprite(SpriteSheetAnimationFactory animationFactory, string playAnimation)
public AnimatedSprite(SpriteSheetAnimationFactory animationFactory, string playAnimation = null)
: base(animationFactory.Frames[0])
{
_animationFactory = animationFactory;
Play(playAnimation).IsLooping = true;
if(playAnimation != null)
Play(playAnimation);
}
private readonly SpriteSheetAnimationFactory _animationFactory;