//public AnimationFrame ToAnimationFrame(TextureAtlas textureAtlas) //{ // AnimationFrame toReturn = ToAnimationFrame(null, false); // var entry = textureAtlas.GetEntryFor(this.TextureName); // if (entry != null) // { // float left; // float right; // float top; // float bottom; // entry.FullToReduced(toReturn.LeftCoordinate, toReturn.RightCoordinate, // toReturn.TopCoordinate, toReturn.BottomCoordinate, // out left, out right, out top, out bottom); // toReturn.LeftCoordinate = left; // toReturn.RightCoordinate = right; // toReturn.TopCoordinate = top; // toReturn.BottomCoordinate = bottom; // } // return toReturn; //} internal static AnimationFrameSave FromXElement(System.Xml.Linq.XElement element) { AnimationFrameSave toReturn = new AnimationFrameSave(); foreach (var subElement in element.Elements()) { switch (subElement.Name.LocalName) { case "FlipHorizontal": toReturn.FlipHorizontal = SceneSave.AsBool(subElement); break; case "FlipVertical": toReturn.FlipVertical = SceneSave.AsBool(subElement); break; case "TextureName": toReturn.TextureName = subElement.Value; break; case "FrameLength": toReturn.FrameLength = SceneSave.AsFloat(subElement); break; case "LeftCoordinate": toReturn.LeftCoordinate = SceneSave.AsFloat(subElement); break; case "RightCoordinate": toReturn.RightCoordinate = SceneSave.AsFloat(subElement); break; case "TopCoordinate": toReturn.TopCoordinate = SceneSave.AsFloat(subElement); break; case "BottomCoordinate": toReturn.BottomCoordinate = SceneSave.AsFloat(subElement); break; case "RelativeX": toReturn.RelativeX = SceneSave.AsFloat(subElement); break; case "RelativeY": toReturn.RelativeY = SceneSave.AsFloat(subElement); break; } } return(toReturn); }
public static AnimationFrameSave ReadAnimationFrameSave(ContentReader input) { FlatRedBall.Content.AnimationChain.AnimationFrameSave newObject = new FlatRedBall.Content.AnimationChain.AnimationFrameSave(); if (input.ReadBoolean()) { newObject.mTextureInstance = input.ReadExternalReference <Microsoft.Xna.Framework.Graphics.Texture2D>(); } newObject.FlipHorizontal = input.ReadBoolean(); newObject.FlipVertical = input.ReadBoolean(); newObject.TextureName = input.ReadString(); newObject.FrameLength = input.ReadSingle(); newObject.LeftCoordinate = input.ReadSingle(); newObject.RightCoordinate = input.ReadSingle(); newObject.TopCoordinate = input.ReadSingle(); newObject.BottomCoordinate = input.ReadSingle(); newObject.RelativeX = input.ReadSingle(); newObject.RelativeY = input.ReadSingle(); return(newObject); }
/// <summary> /// look at all of the textures in each frame and convert them into external references /// </summary> public override AnimationChainListSave Process(AnimationChainListSave input, ContentProcessorContext context) { string directory = System.IO.Path.GetDirectoryName(input.FileName) + @"\"; for (int i = 0; i < input.AnimationChains.Count; i++) { AnimationChainSave ach = input.AnimationChains[i]; List <AnimationFrame> newFrames = new List <AnimationFrame>(ach.Frames.Count); for (int j = 0; j < ach.Frames.Count; j++) { AnimationFrameSave frameSave = new AnimationFrameSave(ach.Frames[j]); frameSave.TextureReference = BitmapTextureProcessor.BuildTexture( directory + frameSave.TextureName, context); newFrames.Add(frameSave); } ach.Frames = newFrames; } return(input); }
public void SetTileX(AnimationFrameSave frame, int valueAsInt) { TileMapInformation information = TileMapInformation; if (information != null) { int pixelPosition = valueAsInt * information.TileWidth; frame.LeftCoordinate = pixelPosition / (float)mTexture.Width; frame.RightCoordinate = frame.LeftCoordinate + (information.TileWidth / (float)mTexture.Width); } }
public void SetTileY(AnimationFrameSave frame, int valueAsInt) { TileMapInformation information = TileMapInformation; if (information != null) { int pixelPosition = valueAsInt * information.TileHeight; frame.TopCoordinate = pixelPosition / (float)mTexture.Height; frame.BottomCoordinate = frame.TopCoordinate + (information.TileHeight / (float)mTexture.Height); } }
public void SetFrame(AnimationFrameSave animationFrameSave, Texture2D texture2D) { mInstance = animationFrameSave; mTexture = texture2D; base.Instance = mInstance; RefreshShownProperties(); }
public Texture2D GetTextureForFrame(AnimationFrameSave frame) { string fileName = GetTextureFileNameForFrame(frame); Texture2D texture = null; if (!string.IsNullOrEmpty(fileName) && System.IO.File.Exists(fileName)) { texture = LoaderManager.Self.LoadContent<Texture2D>(fileName); } return texture; }
public string GetTextureFileNameForFrame(AnimationFrameSave frame) { string returnValue = null; if (ProjectManager.Self.AnimationChainListSave != null) { string achxFolder = FileManager.GetDirectory(ProjectManager.Self.FileName); if (frame != null && !string.IsNullOrEmpty(frame.TextureName)) { string fileName = achxFolder + frame.TextureName; returnValue = fileName; } else { returnValue = null; } } return returnValue; }
private void UpdateSpriteToAnimationFrame(AnimationFrameSave afs, RenderingLibrary.Graphics.Sprite sprite) { sprite.Animate = false; sprite.Texture = WireframeManager.Self.GetTextureForFrame(afs); if (sprite.Texture != null) { sprite.SourceRectangle = GetSourceRetangleForFrame(afs, sprite.Texture); if(sprite.SourceRectangle.HasValue) { sprite.Width = sprite.SourceRectangle.Value.Width; sprite.Height = sprite.SourceRectangle.Value.Height; } } sprite.FlipHorizontal = afs.FlipHorizontal; sprite.FlipVertical = afs.FlipVertical; sprite.Animation = mSprite.Animation; MoveSpriteAccordingToAlignmentAndOffset(sprite, afs); }
public void RefreshTreeNode(AnimationFrameSave animationFrame) { mTreeView.Invoke((MethodInvoker)delegate() { var node = GetTreeNodeFor(animationFrame); node.Text = animationFrame.TextureName; if (string.IsNullOrEmpty(animationFrame.TextureName)) { node.Text = "<UNTEXTURED>"; } else { var texture = WireframeManager.Self.GetTextureForFrame(animationFrame); int left = MathFunctions.RoundToInt(animationFrame.LeftCoordinate * texture.Width); int top = MathFunctions.RoundToInt(animationFrame.TopCoordinate * texture.Height); node.Text += string.Format( " {0},{1}", left, top); } }); }
public void SetTileY(AnimationFrameSave frame, int value) { if (frame == null) { throw new ArgumentNullException("frame", "Argument 'frame' cannot be null"); } mAnimationFrameDisplayer.SetTileY(frame, value); mPropertyGrid.Refresh(); }
public void AdjustFrameToResize(AnimationFrameSave afs, int oldWidth, int oldHeight, int newWidth, int newHeight) { AdjustValue(ref afs.LeftCoordinate, oldWidth, newWidth); AdjustValue(ref afs.RightCoordinate, oldWidth, newWidth); AdjustValue(ref afs.TopCoordinate, oldHeight, newHeight); AdjustValue(ref afs.BottomCoordinate, oldHeight, newHeight); }
public void AddFrameClick(object sender, EventArgs args) { AnimationChainSave chain = SelectedState.Self.SelectedChain; if (string.IsNullOrEmpty(ProjectManager.Self.FileName)) { MessageBox.Show("You must first save this file before adding frames"); } else if (chain == null) { MessageBox.Show("First select an Animation to add a frame to"); } else { AnimationFrameSave afs = new AnimationFrameSave(); if (chain.Frames.Count != 0) { AnimationFrameSave copyFrom = chain.Frames[0]; afs.TextureName = copyFrom.TextureName; afs.FrameLength = copyFrom.FrameLength; afs.LeftCoordinate = copyFrom.LeftCoordinate; afs.RightCoordinate = copyFrom.RightCoordinate; afs.TopCoordinate = copyFrom.TopCoordinate; afs.BottomCoordinate = copyFrom.BottomCoordinate; } else { afs.FrameLength = .1f; // default to .1 seconds. } chain.Frames.Add(afs); TreeViewManager.Self.RefreshTreeNode(chain); SelectedState.Self.SelectedFrame = afs; CallAnimationChainsChange(); } }
private void MoveSpriteAccordingToAlignmentAndOffset(RenderingLibrary.Graphics.Sprite sprite, AnimationFrameSave frame) { // Event though we may not be rendering the main Sprite, we want to use the main Sprite's animation: IAnimation animation = mSprite.Animation; if (sprite != null && sprite.Visible && mSprite.Animation != null) { int index = sprite.Animation.CurrentFrameIndex; float animationXOffset = 0; float animationYOffset = 0; AnimationChainSave chain = SelectedState.Self.SelectedChain; if (chain != null && chain.Frames.Count > index) { if (frame == null) { frame = chain.Frames[index]; } animationXOffset = frame.RelativeX * OffsetMultiplier; animationYOffset = frame.RelativeY * OffsetMultiplier; } if (SpriteAlignment == Data.SpriteAlignment.Center) { float xOffset = (-sprite.EffectiveWidth) / 2.0f; float yOffset = (-sprite.EffectiveHeight) / 2.0f; sprite.X = xOffset + animationXOffset; sprite.Y = yOffset - animationYOffset; } else { sprite.X = 0 + animationXOffset; sprite.Y = 0 - animationYOffset; } } }
private Microsoft.Xna.Framework.Rectangle? GetSourceRetangleForFrame(AnimationFrameSave afs, Microsoft.Xna.Framework.Graphics.Texture2D texture2D) { if (afs == null || texture2D == null) { return null; } else { Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle(); rectangle.X = Math.MathFunctions.RoundToInt(afs.LeftCoordinate * texture2D.Width); rectangle.Width = Math.MathFunctions.RoundToInt(afs.RightCoordinate * texture2D.Width) - rectangle.X; rectangle.Y = Math.MathFunctions.RoundToInt(afs.TopCoordinate * texture2D.Height); rectangle.Height = Math.MathFunctions.RoundToInt(afs.BottomCoordinate * texture2D.Height) - rectangle.Y; return rectangle; } }
//public AnimationFrame ToAnimationFrame(TextureAtlas textureAtlas) //{ // AnimationFrame toReturn = ToAnimationFrame(null, false); // var entry = textureAtlas.GetEntryFor(this.TextureName); // if (entry != null) // { // float left; // float right; // float top; // float bottom; // entry.FullToReduced(toReturn.LeftCoordinate, toReturn.RightCoordinate, // toReturn.TopCoordinate, toReturn.BottomCoordinate, // out left, out right, out top, out bottom); // toReturn.LeftCoordinate = left; // toReturn.RightCoordinate = right; // toReturn.TopCoordinate = top; // toReturn.BottomCoordinate = bottom; // } // return toReturn; //} internal static AnimationFrameSave FromXElement(System.Xml.Linq.XElement element) { AnimationFrameSave toReturn = new AnimationFrameSave(); foreach (var subElement in element.Elements()) { switch (subElement.Name.LocalName) { case "FlipHorizontal": toReturn.FlipHorizontal = SceneSave.AsBool(subElement); break; case "FlipVertical": toReturn.FlipVertical = SceneSave.AsBool(subElement); break; case "TextureName": toReturn.TextureName = subElement.Value; break; case "FrameLength": toReturn.FrameLength = SceneSave.AsFloat(subElement); break; case "LeftCoordinate": toReturn.LeftCoordinate = SceneSave.AsFloat(subElement); break; case "RightCoordinate": toReturn.RightCoordinate = SceneSave.AsFloat(subElement); break; case "TopCoordinate": toReturn.TopCoordinate = SceneSave.AsFloat(subElement); break; case "BottomCoordinate": toReturn.BottomCoordinate = SceneSave.AsFloat(subElement); break; case "RelativeX": toReturn.RelativeX = SceneSave.AsFloat(subElement); break; case "RelativeY": toReturn.RelativeY = SceneSave.AsFloat(subElement); break; } } return toReturn; }
private static void UpdateRectangleSelectorToFrame(AnimationFrameSave frame, Texture2D texture, RectangleSelector rectangleSelector) { rectangleSelector.Visible = texture != null; if (texture != null) { float leftPixel = frame.LeftCoordinate * texture.Width; float rightPixel = frame.RightCoordinate * texture.Width; float topPixel = frame.TopCoordinate * texture.Height; float bottomPixel = frame.BottomCoordinate * texture.Height; rectangleSelector.Left = leftPixel; rectangleSelector.Top = topPixel; rectangleSelector.Width = rightPixel - leftPixel; rectangleSelector.Height = bottomPixel - topPixel; } }
public TreeNode GetTreeNodeFor(AnimationFrameSave afs) { if (afs == null) { return null; } else { return GetTreeNodeByTag(afs, mTreeView.Nodes); } }
private AnimationFrame AnimationFrameSaveToRenderingLibraryAnimationFrame(AnimationFrameSave afs) { AnimationFrame af = new AnimationFrame(); af.Texture = WireframeManager.Self.GetTextureForFrame(afs); af.FlipHorizontal = afs.FlipHorizontal; af.FlipVertical = afs.FlipVertical; af.SourceRectangle = GetSourceRetangleForFrame(afs, af.Texture); af.FrameTime = afs.FrameLength; return af; }