public static AnimationChainList AddAnimationChainList(string fileName) { AnimationChainList sameNamedList = null; foreach (AnimationChainList list in mReferencedAnimationChains) { if (list.Name == fileName) { sameNamedList = list; break; } } if (sameNamedList == null) { AnimationChainListSave animationChainListSave = AnimationChainListSave.FromFile(fileName); AnimationChainList list = animationChainListSave.ToAnimationChainList(SceneContentManager); mReferencedAnimationChains.Add(list); GuiData.ListWindow.Highlight(list); return(list); } else { // highlight the list with the same name GuiData.ListWindow.Highlight(sameNamedList); return(sameNamedList); } }
public TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain> ToAnimationChainGrid(string contentManagerName, float gridSpacing) { TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain> toReturn = new TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain>(); toReturn.FirstPaintedX = FirstPaintedX; toReturn.LastPaintedX = new List <float>(); toReturn.FirstPaintedY = FirstPaintedY; toReturn.LastPaintedY = toReturn.FirstPaintedY + (ReferenceGrid.Length - 1) * gridSpacing; toReturn.GridSpacingX = gridSpacing; toReturn.GridSpacingY = gridSpacing; int yOn = 0; toReturn.BaseTexture = null; Dictionary <string, FlatRedBall.Graphics.Animation.AnimationChainList> animationChainListCache = new Dictionary <string, FlatRedBall.Graphics.Animation.AnimationChainList>(); foreach (ReferencedAnimationChain[] racArray in ReferenceGrid) { List <FlatRedBall.Graphics.Animation.AnimationChain> newAnimationChainList = new List <FlatRedBall.Graphics.Animation.AnimationChain>(); toReturn.Textures.Add(newAnimationChainList); toReturn.LastPaintedX.Add(toReturn.FirstPaintedX[yOn] + gridSpacing * (racArray.Length - 1)); foreach (ReferencedAnimationChain rac in racArray) { FlatRedBall.Graphics.Animation.AnimationChainList acl = null; if (!string.IsNullOrEmpty(rac.AnimationChainListFileName) && animationChainListCache.ContainsKey(rac.AnimationChainListFileName) == false) { AnimationChainListSave acls = AnimationChainListSave.FromFile(rac.AnimationChainListFileName); animationChainListCache.Add(rac.AnimationChainListFileName, acls.ToAnimationChainList(contentManagerName)); } if (string.IsNullOrEmpty(rac.AnimationChainListFileName)) { acl = null; newAnimationChainList.Add(null); } else { acl = animationChainListCache[rac.AnimationChainListFileName]; newAnimationChainList.Add(acl[rac.AnimationChainName]); } } yOn++; } return(toReturn); }
public static SpriteFrame CreateSpriteFrame(string texture, string nameToUse) { SpriteFrame spriteFrame = SpriteManager.AddSpriteFrame(null, SpriteFrame.BorderSides.All); try { if (texture.EndsWith(".ach") || texture.EndsWith(".achx")) { AnimationChainListSave listSave = AnimationChainListSave.FromFile(texture); spriteFrame.AnimationChains = listSave.ToAnimationChainList(SceneContentManager); if (spriteFrame.AnimationChains.Count != 0) { spriteFrame.CurrentChainName = (spriteFrame.AnimationChains[0].Name); } spriteFrame.Animate = true; } else if (texture.EndsWith(".tga") || texture.EndsWith(".png")) { spriteFrame.Texture = FlatRedBallServices.Load <Texture2D>(texture, SceneContentManager); } else { spriteFrame.Texture = FlatRedBallServices.Load <Texture2D>(texture, SceneContentManager); } } catch (Microsoft.DirectX.Direct3D.InvalidDataException) { throw new Microsoft.DirectX.Direct3D.InvalidDataException(); } if (string.IsNullOrEmpty(nameToUse) == false) { spriteFrame.Name = nameToUse; } else { spriteFrame.Name = FileManager.RemovePath(FileManager.RemoveExtension(texture)); } StringFunctions.MakeNameUnique <SpriteFrame>(spriteFrame, mScene.SpriteFrames); spriteFrame.X = Camera.X; spriteFrame.Y = Camera.Y; mScene.SpriteFrames.Add(spriteFrame); return(spriteFrame); }
//public void SetSprite(TextureAtlas textureAtlas, Sprite sprite) //{ // SetSprite("", sprite); // if (!string.IsNullOrEmpty(this.Texture)) // { // var entry = textureAtlas.GetEntryFor(this.Texture); // if (entry != null) // { // float left; // float right; // float top; // float bottom; // entry.FullToReduced(sprite.LeftTextureCoordinate, sprite.RightTextureCoordinate, // sprite.TopTextureCoordinate, sprite.BottomTextureCoordinate, // out left, out right, out top, out bottom); // sprite.LeftTextureCoordinate = left; // sprite.RightTextureCoordinate = right; // sprite.TopTextureCoordinate = top; // sprite.BottomTextureCoordinate = bottom; // sprite.Texture = textureAtlas.Texture; // } // } // if (!string.IsNullOrEmpty(this.AnimationChainsFile)) // { // if (string.IsNullOrEmpty(this.AnimationChainsFile) == false) // { // //AnimationChains = FlatRedBall.Content.AnimationChain.AnimationChainListSave.FromFile(AnimationChainsFile); // AnimationChainListSave acls = AnimationChainListSave.FromFile(this.AnimationChainsFile); // sprite.AnimationChains = acls.ToAnimationChainList(textureAtlas); // } // if (CurrentChain != -1) // { // // Now using the CurrentChainName property so it works with IAnimationChainAnimatable // sprite.CurrentChainName = sprite.AnimationChains[CurrentChain].Name; // //sprite.SetAnimationChain(); // } // } //} internal static void SetRuntimeAnimationChain(string contentManagerName, IAnimationChainAnimatable sprite, AnimationChainList animationChainListInstance, int currentChain, AnimationChainListSave animationChains, string animationChainsFile ) { if (animationChainListInstance != null) { if (animationChainListInstance != null) { sprite.AnimationChains = animationChainListInstance;; } if (currentChain != -1) { // Now using the CurrentChainName property so it works with IAnimationChainAnimatable sprite.CurrentChainName = sprite.AnimationChains[currentChain].Name; //sprite.SetAnimationChain(sprite.AnimationChains[CurrentChain]); } } else if (animationChains != null || string.IsNullOrEmpty(animationChainsFile) == false) { if (animationChains != null && animationChains.FileName != null && animationChains.FileName != "") { // load the AnimationChainArray here // AnimationChains = new AnimationChainList(saveToSetFrom.animationChains.Name); sprite.AnimationChains = animationChains.ToAnimationChainList(contentManagerName); sprite.AnimationChains.Name = FlatRedBall.IO.FileManager.Standardize(animationChains.FileName); } else if (string.IsNullOrEmpty(animationChainsFile) == false) { //AnimationChains = FlatRedBall.Content.AnimationChain.AnimationChainListSave.FromFile(AnimationChainsFile); sprite.AnimationChains = FlatRedBallServices.Load <AnimationChainList>( animationChainsFile, contentManagerName); } if (currentChain != -1) { // Now using the CurrentChainName property so it works with IAnimationChainAnimatable sprite.CurrentChainName = sprite.AnimationChains[currentChain].Name; //sprite.SetAnimationChain(); } } }
public static void AddSprite(string textureOrAnimationFile) { Sprite newSprite = null; if (FileManager.GetExtension(textureOrAnimationFile) == "achx") { AnimationChainListSave achs = AnimationChainListSave.FromFile(textureOrAnimationFile); newSprite = SpriteManager.AddSprite( achs.ToAnimationChainList(ContentManagerName)); mBlockingScene.Sprites.Add(newSprite); newSprite.Name = FileManager.RemovePath(FileManager.RemoveExtension(textureOrAnimationFile)); } else { newSprite = SpriteManager.AddSprite(textureOrAnimationFile, ContentManagerName); mBlockingScene.Sprites.Add(newSprite); newSprite.Name = FileManager.RemovePath(FileManager.RemoveExtension(textureOrAnimationFile)); } SetNewlyCreatedSpriteProperties(newSprite); }
protected override AnimationChainList Read(ContentReader input, AnimationChainList existingInstance) { if (existingInstance != null) { return(existingInstance); } AnimationChainListSave acls = null; if (ObjectReader.UseReflection) { acls = ObjectReader.ReadObject <AnimationChainListSave>(input); } else { acls = ReadAnimationChainListSave(input); } acls.FileName = input.AssetName; return(acls.ToAnimationChainList("")); /* * //read list of animation chains * TimeMeasurementUnit timeMeasurement = (TimeMeasurementUnit)input.ReadInt32(); * float divisor = timeMeasurement == TimeMeasurementUnit.Millisecond ? 1000 : 1; * * int chainsCount = input.ReadInt32(); * existingInstance = new AnimationChainList(chainsCount); * existingInstance.TimeMeasurementUnit = timeMeasurement; * * existingInstance.Name = input.AssetName; * * for (int i = 0; i < chainsCount; i++) * { * //read list of Frames * int frameCount = input.ReadInt32(); * FlatRedBall.Graphics.Animation.AnimationChain ach = * new FlatRedBall.Graphics.Animation.AnimationChain(frameCount); * * ach.Name = input.ReadString(); * * for (int j = 0; j < frameCount; j++) * { * AnimationFrame frame = new AnimationFrame( * input.ReadExternalReference<Texture2D>(), * input.ReadSingle()); * frame.FrameLength /= divisor; * frame.FlipHorizontal = input.ReadBoolean(); * frame.FlipVertical = input.ReadBoolean(); * * frame.LeftCoordinate = input.ReadSingle(); * frame.RightCoordinate = input.ReadSingle(); * frame.TopCoordinate = input.ReadSingle(); * frame.BottomCoordinate = input.ReadSingle(); * * frame.RelativeX = input.ReadSingle(); * frame.RelativeY = input.ReadSingle(); * * ach.Add(frame); * } * existingInstance.Add(ach); * } * * return existingInstance; */ }
public static Sprite AddSprite(string spriteTexture, string nameToUse) { EditorSprite spriteCreated = new EditorSprite(); #region Create the spriteCreated depending on the type in spriteTexture try { #region Is the texture null? if (string.IsNullOrEmpty(spriteTexture)) { spriteCreated.Texture = null; spriteCreated.Red = GraphicalEnumerations.MaxColorComponentValue; spriteCreated.ColorOperation = Microsoft.DirectX.Direct3D.TextureOperation.SelectArg2; } #endregion #region Create the Sprite with a .achx else if (spriteTexture.EndsWith(".ach") || spriteTexture.EndsWith(".achx") || spriteTexture.EndsWith(".gif")) { if (spriteTexture.EndsWith(".gif")) { AnimationChain animationChain = AnimationChain.FromGif(spriteTexture, SceneContentManager); spriteCreated.SetAnimationChain(animationChain); } else { AnimationChainListSave listSave = AnimationChainListSave.FromFile(spriteTexture); spriteCreated.AnimationChains = listSave.ToAnimationChainList(SceneContentManager); } if (spriteCreated.AnimationChains.Count != 0) { spriteCreated.SetAnimationChain(spriteCreated.AnimationChains[0]); } spriteCreated.Animate = true; } #endregion #region Create the Sprite with an image else { spriteCreated.Texture = FlatRedBallServices.Load <Texture2D>(spriteTexture, SceneContentManager); } #endregion } catch (Microsoft.DirectX.Direct3D.InvalidDataException) { throw new Microsoft.DirectX.Direct3D.InvalidDataException(); } #endregion SpriteManager.AddSprite(spriteCreated); KeepSpriteNameUnique <Sprite>(spriteCreated, nameToUse, mScene.Sprites); spriteCreated.X = Camera.X; spriteCreated.Y = Camera.Y; // If the camera's in ortho mode then we're likely making a 2D game, so set the PixelSize to .5 if (SpriteManager.Camera.Orthogonal) { spriteCreated.PixelSize = .5f; } SetStoredAddToSE(spriteCreated, EditorProperties.PixelSize); return(spriteCreated); }