public static AnimationChain FromGif(string fileName, string contentManagerName) { if (FileManager.IsRelative(fileName)) { fileName = FileManager.RelativeDirectory + fileName; } if (FlatRedBallServices.IsLoaded<AnimationChain>(fileName, contentManagerName)) { return FlatRedBallServices.GetNonDisposable<AnimationChain>(fileName, contentManagerName).Clone(); } ImageDataList imageDataList = GifLoader.GetImageDataList(fileName); int numberOfFrames = imageDataList.Count; AnimationChain animationChain = new AnimationChain(numberOfFrames); for (int i = 0; i < numberOfFrames; i++) { // We assume GIFs are for 2D games that don't need mipmaps. Could change this later // if needed const bool generateMipmaps = false; Texture2D texture2D = imageDataList[i].ToTexture2D(generateMipmaps, FlatRedBallServices.GraphicsDevice); texture2D.Name = fileName + i.ToString(); if (i >= imageDataList.FrameTimes.Count) { const double defaultFrameTime = .1; animationChain.Add( new AnimationFrame( texture2D, (float)defaultFrameTime)); } else { animationChain.Add( new AnimationFrame( texture2D, (float)imageDataList.FrameTimes[i])); } FlatRedBallServices.AddDisposable(texture2D.Name, texture2D, contentManagerName); } // Don't dispose the anything because it's part of the // content manager. animationChain.ParentGifFileName = fileName; animationChain.Name = FileManager.RemovePath(fileName); return animationChain; }
void CustomInitialize() { InitializeLevel("Level1"); foreach (var item in Level1Info) { if(item.EmbeddedAnimation != null && item.EmbeddedAnimation.Count != 0) { AnimationChain animationChain = new AnimationChain(); foreach(var frame in item.EmbeddedAnimation) { } } } }
/// <summary> /// Returns a clone of this instance. /// </summary> /// <remarks> /// Attachments are not cloned. The new clone /// will not have any parents or children. /// </remarks> /// <returns>The new clone.</returns> #endregion public Sprite Clone() { Sprite sprite = base.Clone <Sprite>(); sprite.Texture = Texture; sprite.FlipHorizontal = FlipHorizontal; sprite.FlipVertical = FlipVertical; sprite.ColorOperation = mColorOperation; // Although the Scale has already been set at this point, set it again so that it will // override the PixelSize IF the PixelSize is being overridden by the current scale: sprite.ScaleX = ScaleX; sprite.ScaleY = ScaleY; sprite.TimeCreated = TimeManager.CurrentTime; sprite.mVertices = new SpriteVertex[4]; for (int i = 0; i < 4; i++) { sprite.mVertices[i] = new SpriteVertex(mVertices[i]); } sprite.mVerticesForDrawing = new VertexPositionColorTexture[4]; sprite.mAnimationChains = new AnimationChainList(); for (int i = 0; i < mAnimationChains.Count; i++) { AnimationChain ac = mAnimationChains[i]; sprite.mAnimationChains.Add(ac); } if (CustomBehavior != null) { #if XNA4 throw new NotSupportedException("Sprite custom behavior is not supported in XNA 4"); #else sprite.CustomBehavior = CustomBehavior.Clone() as SpriteCustomBehavior; #endif } return(sprite); }
internal static AnimationChainSave FromAnimationChain(Anim.AnimationChain animationChain, TimeMeasurementUnit timeMeasurementUnit) { AnimationChainSave animationChainSave = new AnimationChainSave(); animationChainSave.Frames = new List <AnimationFrameSave>(); animationChainSave.Name = animationChain.Name; foreach (Anim.AnimationFrame frame in animationChain) { AnimationFrameSave save = new AnimationFrameSave(frame); animationChainSave.Frames.Add(save); } if (!string.IsNullOrEmpty(animationChain.ParentGifFileName)) { animationChainSave.ParentFile = animationChain.ParentGifFileName; } return(animationChainSave); }
protected override void InitializeEntity(bool addToManagers) { LoadStaticContent(ContentManagerName); AnimationChainInstance = new FlatRedBall.Graphics.Animation.AnimationChain(); AnimationChainInstance.Name = "AnimationChainInstance"; base.InitializeEntity(addToManagers); if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteXReset = LightOrShadowSprite.X; } else { LightOrShadowSpriteXReset = LightOrShadowSprite.RelativeX; } if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteYReset = LightOrShadowSprite.Y; } else { LightOrShadowSpriteYReset = LightOrShadowSprite.RelativeY; } if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteZReset = LightOrShadowSprite.Z; } else { LightOrShadowSpriteZReset = LightOrShadowSprite.RelativeZ; } if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteXVelocityReset = LightOrShadowSprite.XVelocity; } else { LightOrShadowSpriteXVelocityReset = LightOrShadowSprite.RelativeXVelocity; } if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteYVelocityReset = LightOrShadowSprite.YVelocity; } else { LightOrShadowSpriteYVelocityReset = LightOrShadowSprite.RelativeYVelocity; } if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteZVelocityReset = LightOrShadowSprite.ZVelocity; } else { LightOrShadowSpriteZVelocityReset = LightOrShadowSprite.RelativeZVelocity; } if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteRotationXReset = LightOrShadowSprite.RotationX; } else { LightOrShadowSpriteRotationXReset = LightOrShadowSprite.RelativeRotationX; } if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteRotationYReset = LightOrShadowSprite.RotationY; } else { LightOrShadowSpriteRotationYReset = LightOrShadowSprite.RelativeRotationY; } if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteRotationZReset = LightOrShadowSprite.RotationZ; } else { LightOrShadowSpriteRotationZReset = LightOrShadowSprite.RelativeRotationZ; } if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteRotationXVelocityReset = LightOrShadowSprite.RotationXVelocity; } else { LightOrShadowSpriteRotationXVelocityReset = LightOrShadowSprite.RelativeRotationXVelocity; } if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteRotationYVelocityReset = LightOrShadowSprite.RotationYVelocity; } else { LightOrShadowSpriteRotationYVelocityReset = LightOrShadowSprite.RelativeRotationYVelocity; } if (LightOrShadowSprite.Parent == null) { LightOrShadowSpriteRotationZVelocityReset = LightOrShadowSprite.RotationZVelocity; } else { LightOrShadowSpriteRotationZVelocityReset = LightOrShadowSprite.RelativeRotationZVelocity; } LightOrShadowSpriteAlphaReset = LightOrShadowSprite.Alpha; LightOrShadowSpriteAlphaRateReset = LightOrShadowSprite.AlphaRate; if (SpriteInstance.Parent == null) { SpriteInstanceXReset = SpriteInstance.X; } else { SpriteInstanceXReset = SpriteInstance.RelativeX; } if (SpriteInstance.Parent == null) { SpriteInstanceYReset = SpriteInstance.Y; } else { SpriteInstanceYReset = SpriteInstance.RelativeY; } if (SpriteInstance.Parent == null) { SpriteInstanceZReset = SpriteInstance.Z; } else { SpriteInstanceZReset = SpriteInstance.RelativeZ; } if (SpriteInstance.Parent == null) { SpriteInstanceXVelocityReset = SpriteInstance.XVelocity; } else { SpriteInstanceXVelocityReset = SpriteInstance.RelativeXVelocity; } if (SpriteInstance.Parent == null) { SpriteInstanceYVelocityReset = SpriteInstance.YVelocity; } else { SpriteInstanceYVelocityReset = SpriteInstance.RelativeYVelocity; } if (SpriteInstance.Parent == null) { SpriteInstanceZVelocityReset = SpriteInstance.ZVelocity; } else { SpriteInstanceZVelocityReset = SpriteInstance.RelativeZVelocity; } if (SpriteInstance.Parent == null) { SpriteInstanceRotationXReset = SpriteInstance.RotationX; } else { SpriteInstanceRotationXReset = SpriteInstance.RelativeRotationX; } if (SpriteInstance.Parent == null) { SpriteInstanceRotationYReset = SpriteInstance.RotationY; } else { SpriteInstanceRotationYReset = SpriteInstance.RelativeRotationY; } if (SpriteInstance.Parent == null) { SpriteInstanceRotationZReset = SpriteInstance.RotationZ; } else { SpriteInstanceRotationZReset = SpriteInstance.RelativeRotationZ; } if (SpriteInstance.Parent == null) { SpriteInstanceRotationXVelocityReset = SpriteInstance.RotationXVelocity; } else { SpriteInstanceRotationXVelocityReset = SpriteInstance.RelativeRotationXVelocity; } if (SpriteInstance.Parent == null) { SpriteInstanceRotationYVelocityReset = SpriteInstance.RotationYVelocity; } else { SpriteInstanceRotationYVelocityReset = SpriteInstance.RelativeRotationYVelocity; } if (SpriteInstance.Parent == null) { SpriteInstanceRotationZVelocityReset = SpriteInstance.RotationZVelocity; } else { SpriteInstanceRotationZVelocityReset = SpriteInstance.RelativeRotationZVelocity; } SpriteInstanceAlphaReset = SpriteInstance.Alpha; SpriteInstanceAlphaRateReset = SpriteInstance.AlphaRate; CircleInstanceRadiusReset = CircleInstance.Radius; CircleInstanceVisibleReset = CircleInstance.Visible; }
public void SetAnimationChain(AnimationChain chainToSet, double timeIntoAnimation) { if (chainToSet != null) { mCurrentFrameIndex = 0; SetAnimationChain(chainToSet); mTimeIntoAnimation = timeIntoAnimation; UpdateFrameBasedOffOfTimeIntoAnimation(); } }
/// <summary> /// Sets the argument chainToSet as the animationChain. If the argument chainToSet is not /// part of the Sprite's internal list of AnimationChains, it is added. /// </summary> /// <remarks> /// This differs from FlatRedBall MDX - this method on FlatRedBall MDX does not add the argument /// AnimationChain to the Sprite's internal list. /// <para> /// This does not set any animation-related properties, but it does set the current /// texture to the current frame's texture. Therefore, it is still necessary to set Animate to true. /// </para> /// </remarks> /// <param name="chainToSet">The AnimationChain to set as the current AnimationChain. This is /// added to the internal AnimationChains property if it is not already there.</param> #endregion public void SetAnimationChain(AnimationChain chainToSet) { if (chainToSet != null) { int index = mAnimationChains.IndexOf(chainToSet); if (index != -1) mCurrentChainIndex = index; else { mAnimationChains.Add(chainToSet); mCurrentChainIndex = mAnimationChains.Count - 1; } mTimeIntoAnimation = 0; mCurrentFrameIndex = 0; UpdateToCurrentAnimationFrame(); } }
/// <summary> /// Removes the AnimationChain from the Sprite's internal AnimationChain List. /// </summary> /// <remarks> /// If the chainToRemove is also the CurrentChain, the animate field /// is set to false. /// </remarks> /// <param name="chainToRemove">The AnimationChain to remove.</param> #endregion public void RemoveAnimationChain(AnimationChain chainToRemove) { int index = mAnimationChains.IndexOf(chainToRemove); if (mAnimationChains.Contains(chainToRemove)) { mAnimationChains.Remove(chainToRemove); } if (index == mCurrentChainIndex) { mCurrentChainIndex = -1; mAnimate = false; } }
public void SetOverlayAnimationChain(AnimationChain achToSet) { throw new NotImplementedException(); //mSprite.SetAnimationChain(achToSet, TimeManager.CurrentTime); }
public AnimationChainContainer(AnimationChain animationChain) { this.AnimationChain = animationChain; AnimationSpeed = 1; CurrentFrameIndex = 1; }
bool IEquatable <AnimationChain> .Equals(AnimationChain other) { return(this == other); }
public static LayeredTileMap FromTiledMapSave(string fileName, string contentManager) { TiledMapSave tms = TiledMapSave.FromFile(fileName); // Ultimately properties are tied to tiles by the tile name. // If a tile has no name but it has properties, those properties // will be lost in the conversion. Therefore, we have to add name properties. tms.NameUnnamedTilesetTiles(); string directory = FlatRedBall.IO.FileManager.GetDirectory(fileName); var rtmi = ReducedTileMapInfo.FromTiledMapSave( tms, 1, 0, directory, FileReferenceType.Absolute); var toReturn = FromReducedTileMapInfo(rtmi, contentManager, fileName); foreach (var mapObjectgroup in tms.objectgroup) { var shapeCollection = tms.ToShapeCollection(mapObjectgroup.Name); if (shapeCollection != null && shapeCollection.IsEmpty == false) { shapeCollection.Name = mapObjectgroup.Name; toReturn.ShapeCollections.Add(shapeCollection); } } foreach (var layer in tms.MapLayers) { var matchingLayer = toReturn.MapLayers.FirstOrDefault(item => item.Name == layer.Name); if (matchingLayer != null) { if (layer is MapLayer) { var mapLayer = layer as MapLayer; foreach (var propertyValues in mapLayer.properties) { matchingLayer.Properties.Add(new NamedValue { Name = propertyValues.StrippedName, Value = propertyValues.value, Type = propertyValues.Type }); } matchingLayer.Visible = mapLayer.visible == 1; } } } foreach (var tileset in tms.Tilesets) { foreach (var tile in tileset.TileDictionary.Values) { if (tile.properties.Count != 0) { // this needs a name: string name = tile.properties.FirstOrDefault(item => item.StrippedName.ToLowerInvariant() == "name")?.value; if (!string.IsNullOrEmpty(name)) { List<NamedValue> namedValues = new List<NamedValue>(); foreach (var prop in tile.properties) { namedValues.Add(new NamedValue() { Name = prop.StrippedName, Value = prop.value, Type = prop.Type }); } toReturn.Properties.Add(name, namedValues); } } } } var tmxDirectory = FileManager.GetDirectory(fileName); var animationDictionary = new Dictionary<string, AnimationChain>(); // add animations foreach (var tileset in tms.Tilesets) { string tilesetImageFile = tmxDirectory + tileset.Images[0].Source; if (tileset.SourceDirectory != ".") { tilesetImageFile = tmxDirectory + tileset.SourceDirectory + tileset.Images[0].Source; } var texture = FlatRedBallServices.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(tilesetImageFile); foreach (var tile in tileset.Tiles.Where(item => item.Animation != null && item.Animation.Frames.Count != 0)) { var animation = tile.Animation; var animationChain = new AnimationChain(); foreach (var frame in animation.Frames) { var animationFrame = new AnimationFrame(); animationFrame.FrameLength = frame.Duration / 1000.0f; animationFrame.Texture = texture; int tileIdRelative = frame.TileId; int globalTileId = (int)(tileIdRelative + tileset.Firstgid); int leftPixel; int rightPixel; int topPixel; int bottomPixel; TiledMapSave.GetPixelCoordinatesFromGid((uint)globalTileId, tileset, out leftPixel, out topPixel, out rightPixel, out bottomPixel); animationFrame.LeftCoordinate = MapDrawableBatch.CoordinateAdjustment + leftPixel / (float)texture.Width; animationFrame.RightCoordinate = -MapDrawableBatch.CoordinateAdjustment + rightPixel / (float)texture.Width; animationFrame.TopCoordinate = MapDrawableBatch.CoordinateAdjustment + topPixel / (float)texture.Height; animationFrame.BottomCoordinate = -MapDrawableBatch.CoordinateAdjustment + bottomPixel / (float)texture.Height; animationChain.Add(animationFrame); } var property = tile.properties.FirstOrDefault(item => item.StrippedNameLower == "name"); if (property == null) { throw new InvalidOperationException( $"The tile with ID {tile.id} has an animation, but it doesn't have a Name property, which is required for animation."); } else { animationDictionary.Add(property.value, animationChain); } } } toReturn.Animation = new LayeredTileMapAnimation(animationDictionary); toReturn.MapProperties = tms.properties .Select(propertySave => new NamedValue { Name = propertySave.name, Value = propertySave.value, Type = propertySave.Type }) .ToList(); return toReturn; }
public Anim.AnimationChain ToAnimationChain(string contentManagerName, TimeMeasurementUnit timeMeasurementUnit, TextureCoordinateType coordinateType) { if (!string.IsNullOrEmpty(ParentFile)) { #if !WINDOWS_8 && !UWP && !DESKTOP_GL FlatRedBall.Graphics.Animation.AnimationChain animationChain = FlatRedBall.Graphics.Animation.AnimationChain.FromGif( ParentFile, contentManagerName); animationChain.Name = Name; animationChain.ParentGifFileName = ParentFile; if (animationChain.Count == this.Frames.Count) { for (int i = 0; i < animationChain.Count; i++) { animationChain[i].FlipHorizontal = Frames[i].FlipHorizontal; animationChain[i].FlipVertical = Frames[i].FlipVertical; animationChain[i].FrameLength = Frames[i].FrameLength; animationChain[i].RelativeX = Frames[i].RelativeX; animationChain[i].RelativeY = Frames[i].RelativeY; animationChain[i].TopCoordinate = Frames[i].TopCoordinate; animationChain[i].BottomCoordinate = Frames[i].BottomCoordinate; animationChain[i].LeftCoordinate = Frames[i].LeftCoordinate; animationChain[i].RightCoordinate = Frames[i].RightCoordinate; } } return(animationChain); #else throw new NotImplementedException(); #endif } else { Anim.AnimationChain animationChain = new Anim.AnimationChain(); animationChain.Name = Name; float divisor = 1; if (timeMeasurementUnit == TimeMeasurementUnit.Millisecond) { divisor = 1000; } foreach (AnimationFrameSave save in Frames) { // process the AnimationFrame and add it to the newly-created AnimationChain AnimationFrame frame = null; bool loadTexture = true; frame = save.ToAnimationFrame(contentManagerName, loadTexture, coordinateType); frame.FrameLength /= divisor; animationChain.Add(frame); } return(animationChain); } }