protected override SpriteSheetAnimationFactory Read(ContentReader reader, SpriteSheetAnimationFactory existingInstance) { var relativeName = reader.ReadString(); var textureAtlasAssetName = reader.GetRelativeAssetName(relativeName); var textureAtlas = reader.ContentManager.Load <TextureAtlas>(textureAtlasAssetName); var frameCount = reader.ReadInt32(); var regions = new List <TextureRegion2D>(); for (var i = 0; i < frameCount; i++) { var frameName = reader.ReadString(); var textureRegion = textureAtlas[frameName]; regions.Add(textureRegion); } var animationFactory = new SpriteSheetAnimationFactory(regions); var animationCount = reader.ReadInt32(); for (var i = 0; i < animationCount; i++) { var name = reader.ReadString(); var framesPerSecond = reader.ReadInt32(); var isLooping = reader.ReadBoolean(); var isReversed = reader.ReadBoolean(); var isPingPong = reader.ReadBoolean(); var frameDuration = 1.0f / framesPerSecond; var frameIndexCount = reader.ReadInt32(); var frameIndicies = new int[frameIndexCount]; for (var f = 0; f < frameIndexCount; f++) { var frameIndex = reader.ReadInt32(); frameIndicies[f] = frameIndex; } var animationData = new SpriteSheetAnimationData(frameIndicies, frameDuration, isLooping, isReversed, isPingPong); animationFactory.Add(name, animationData); } return(animationFactory); }
public void Add(string name, SpriteSheetAnimationData data) { _animationDataDictionary.Add(name, data); }
public SpriteSheetAnimation(string name, TextureRegion2D[] keyFrames, SpriteSheetAnimationData data) : this(name, keyFrames, data.FrameDuration, data.IsLooping, data.IsReversed, data.IsPingPong) { }