private static SpriteAnimation CreateAnimation() { var texture1 = Substitute.For <ITexture>(); var sprite1 = new Sprite(texture1, Vector2.Zero, Vector2.Zero, Vector2.Zero, 0); var frame1 = new SpriteAnimationFrame(sprite1, 1); var texture2 = Substitute.For <ITexture>(); var sprite2 = new Sprite(texture2, Vector2.Zero, Vector2.Zero, Vector2.Zero, 0); var frame2 = new SpriteAnimationFrame(sprite2, 1); var frames = new[] { frame1, frame2 }; return(new SpriteAnimation(frames, TimeSpan.FromSeconds(1))); }
public static SpriteAnimationData CreateAnimation(Texture2D atlas, ref SpriteAnimationConfig config) { SpriteAnimationData result = null; if (config.TileCount > 0 || config.TileDim.X > 0 || config.TileDim.Y > 0) { result = new SpriteAnimationData() { Config = config }; result.Frames.Capacity = config.TileCount; int numCols = atlas.Width / config.TileDim.X; int numRows = atlas.Height / config.TileDim.Y; result.TileSheet = atlas; int spriteIndex = 0; for (int row = 0; row < numRows; row++) { for (int col = 0; col < numCols; col++, spriteIndex++) { if (spriteIndex >= config.TileCount) { goto DONE_LABEL; } SpriteAnimationFrame frame = new SpriteAnimationFrame { Offset = new Point(col, row) * config.TileDim }; result.Frames.Add(frame); } } DONE_LABEL :; } return(result); }
public void addAnimation(string name, SpriteAnimationFrame[] animation) { animations.Add( name, animation ); }