public IAnimation Clone() { AGSAnimation clone = (AGSAnimation)MemberwiseClone(); clone.Frames = new List <IAnimationFrame> (Frames.Count); foreach (var frame in Frames) { clone.Frames.Add(frame.Clone()); } return(clone); }
private AGSAnimation getAnimation(string samplePath, IAnimationConfiguration animationConfig, int resourcesCount) { if (resourcesCount == 0 && samplePath != null) { throw new InvalidOperationException($"Failed to load animation from: {samplePath}"); } animationConfig = animationConfig ?? new AGSAnimationConfiguration(); AGSAnimationState state = new AGSAnimationState(); AGSAnimation animation = new AGSAnimation(animationConfig, state, resourcesCount); return(animation); }
private void addAnimationFrame(IImage image, AGSAnimation animation) { if (image == null) { return; } ISprite sprite = GetSprite(); sprite.Image = image; AGSAnimationFrame frame = new AGSAnimationFrame(sprite); animation.Frames.Add(frame); }
private IAnimation loadAnimationFromResources(string samplePath, List <IResource> resources, IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null) { AGSAnimation animation = getAnimation(samplePath, animationConfig, resources.Count); foreach (IResource resource in resources) { var image = loadImage(resource, loadConfig); addAnimationFrame(image, animation); } animation.Setup(); return(animation); }
public IAnimation ToItem(AGSSerializationContext context) { AGSAnimation animation = new AGSAnimation(Configuration.ToItem(context), State.ToItem(context), Frames == null ? 0 : Frames.Count); if (Frames != null) { foreach (var frame in Frames) { animation.Frames.Add(frame.ToItem(context)); } } return(animation); }
public void SetupAnimationTest(LoopingStyle looping, int expectedFrame, bool expectedBackwards) { AGSAnimationConfiguration config = new AGSAnimationConfiguration { Looping = looping, DelayBetweenFrames = 0 }; AGSAnimationState state = new AGSAnimationState (); AGSAnimation animation = new AGSAnimation (config, state); for (int i = 0; i < 5; i++) { animation.Frames.Add(getFrame(i * 2)); } animation.Setup(); Assert.AreEqual(expectedFrame, state.CurrentFrame); Assert.AreEqual(0, state.CurrentLoop); Assert.AreEqual(expectedBackwards, state.RunningBackwards); Assert.AreEqual(expectedFrame * 2, state.TimeToNextFrame); }
private void getSpriteSheetData(IBitmap bitmap, ISpriteSheet spriteSheet, IAnimationConfiguration animationConfig, out int cellsInRow, out int cellsInCol, out int cellsTotal, out int cellX, out int cellY, out int cellsToGrab, out Point mainStep, out Point secondStep, out AGSAnimation animation) { cellsInRow = bitmap.Width / spriteSheet.CellWidth; cellsInCol = bitmap.Height / spriteSheet.CellHeight; cellsTotal = cellsInRow * cellsInCol; int startRow, startCol; getOrder(spriteSheet.Order, cellsInRow, cellsInCol, out startRow, out startCol, out mainStep, out secondStep); cellX = startCol; cellY = startRow; cellsToGrab = spriteSheet.CellsToGrab < 0 ? cellsTotal : Math.Min(spriteSheet.CellsToGrab, cellsTotal); animation = new AGSAnimation(animationConfig, new AGSAnimationState(), cellsToGrab); }
public void NextFrameTest(LoopingStyle looping, int loops, int currentFrame, int currentLoop, bool runningBackwards, int expectedFrame, int expectedLoop, bool expectedBackwards) { AGSAnimationConfiguration config = new AGSAnimationConfiguration { Looping = looping, Loops = loops, DelayBetweenFrames = 0 }; AGSAnimationState state = new AGSAnimationState { CurrentFrame = currentFrame, CurrentLoop = currentLoop, RunningBackwards = runningBackwards, TimeToNextFrame = currentFrame * 2 }; AGSAnimation animation = new AGSAnimation (config, state); for (int i = 0; i < 5; i++) { animation.Frames.Add(getFrame(i * 2)); } animation.NextFrame(); Assert.AreEqual(expectedFrame, state.CurrentFrame); Assert.AreEqual(expectedLoop, state.CurrentLoop); Assert.AreEqual(expectedBackwards, state.RunningBackwards); Assert.AreEqual(expectedFrame * 2, state.TimeToNextFrame); }
private void addAnimationFrame (IImage image, AGSAnimation animation) { if (image == null) return; ISprite sprite = GetSprite (); sprite.Image = image; AGSAnimationFrame frame = new AGSAnimationFrame (sprite); animation.Frames.Add (frame); }
private AGSAnimation getAnimation (IAnimationConfiguration animationConfig, int resourcesCount) { animationConfig = animationConfig ?? new AGSAnimationConfiguration (); AGSAnimationState state = new AGSAnimationState (); AGSAnimation animation = new AGSAnimation (animationConfig, state, resourcesCount); return animation; }
private void getSpriteSheetData (IBitmap bitmap, ISpriteSheet spriteSheet, IAnimationConfiguration animationConfig, out int cellsInRow, out int cellsInCol, out int cellsTotal, out int cellX, out int cellY, out int cellsToGrab, out Point mainStep, out Point secondStep, out AGSAnimation animation) { cellsInRow = bitmap.Width / spriteSheet.CellWidth; cellsInCol = bitmap.Height / spriteSheet.CellHeight; cellsTotal = cellsInRow * cellsInCol; int startRow, startCol; getOrder (spriteSheet.Order, cellsInRow, cellsInCol, out startRow, out startCol, out mainStep, out secondStep); cellX = startCol; cellY = startRow; cellsToGrab = spriteSheet.CellsToGrab < 0 ? cellsTotal : Math.Min (spriteSheet.CellsToGrab, cellsTotal); animation = new AGSAnimation (animationConfig, new AGSAnimationState (), cellsToGrab); }