public AnimationFrame ToAnimationFrame(string contentManagerName, bool loadTexture, TextureCoordinateType coordinateType) { AnimationFrame frame = new AnimationFrame(); #region Set basic variables frame.TextureName = TextureName; frame.FrameLength = FrameLength; if (loadTexture) { if (mTextureInstance != null) { frame.Texture = mTextureInstance; } // I think we should tolarte frames with a null Texture else if (!string.IsNullOrEmpty(TextureName)) { //throw new NotImplementedException(); //frame.Texture = FlatRedBallServices.Load<Texture2D>(TextureName, contentManagerName); try { var fileName = ToolsUtilities.FileManager.RemoveDotDotSlash(ToolsUtilities.FileManager.RelativeDirectory + TextureName); frame.Texture = global::RenderingLibrary.Content.LoaderManager.Self.LoadContent <Microsoft.Xna.Framework.Graphics.Texture2D>( fileName); } catch (System.IO.FileNotFoundException) { if (Wireframe.GraphicalUiElement.MissingFileBehavior == Wireframe.MissingFileBehavior.ThrowException) { string message = $"Error loading texture in animation :\n{TextureName}"; throw new System.IO.FileNotFoundException(message); } frame.Texture = null; } } //frame.Texture = FlatRedBallServices.Load<Texture2D>(TextureName, contentManagerName); } frame.FlipHorizontal = FlipHorizontal; frame.FlipVertical = FlipVertical; if (coordinateType == TextureCoordinateType.UV) { frame.LeftCoordinate = LeftCoordinate; frame.RightCoordinate = RightCoordinate; frame.TopCoordinate = TopCoordinate; frame.BottomCoordinate = BottomCoordinate; } else if (coordinateType == TextureCoordinateType.Pixel) { // April 16, 2015 // Victor Chelaru // We used to throw this exception, but I don't know why we should, because // the Sprite won't show up, and the problem should be discoverable in tools // without a crash //if (frame.Texture == null) //{ // throw new Exception("The frame must have its texture loaded to use the Pixel coordinate type"); //} if (frame.Texture != null) { frame.LeftCoordinate = LeftCoordinate / frame.Texture.Width; frame.RightCoordinate = RightCoordinate / frame.Texture.Width; frame.TopCoordinate = TopCoordinate / frame.Texture.Height; frame.BottomCoordinate = BottomCoordinate / frame.Texture.Height; } } frame.RelativeX = RelativeX; frame.RelativeY = RelativeY; #endregion return(frame); }
public AnimationFrame ToAnimationFrame(string contentManagerName, bool loadTexture, TextureCoordinateType coordinateType) { AnimationFrame frame = new AnimationFrame(); #region Set basic variables frame.TextureName = TextureName; frame.FrameLength = FrameLength; if (loadTexture) { #if FRB_MDX frame.Texture = FlatRedBallServices.Load<Texture2D>(TextureName, contentManagerName); #else if (mTextureInstance != null) { frame.Texture = mTextureInstance; } // I think we should tolarte frames with a null Texture else if (!string.IsNullOrEmpty(TextureName)) { #if IOS || ANDROID frame.Texture = FlatRedBallServices.Load<Texture2D>(TextureName.ToLowerInvariant(), contentManagerName); #else frame.Texture = FlatRedBallServices.Load<Texture2D>(TextureName, contentManagerName); #endif } //frame.Texture = FlatRedBallServices.Load<Texture2D>(TextureName, contentManagerName); #endif } frame.FlipHorizontal = FlipHorizontal; frame.FlipVertical = FlipVertical; if (coordinateType == TextureCoordinateType.UV) { frame.LeftCoordinate = LeftCoordinate; frame.RightCoordinate = RightCoordinate; frame.TopCoordinate = TopCoordinate; frame.BottomCoordinate = BottomCoordinate; } else if (coordinateType == TextureCoordinateType.Pixel) { // April 16, 2015 // Victor Chelaru // We used to throw this exception, but I don't know why we should, because // the Sprite won't show up, and the problem should be discoverable in tools // without a crash //if (frame.Texture == null) //{ // throw new Exception("The frame must have its texture loaded to use the Pixel coordinate type"); //} if (frame.Texture != null) { frame.LeftCoordinate = LeftCoordinate / frame.Texture.Width; frame.RightCoordinate = RightCoordinate / frame.Texture.Width; frame.TopCoordinate = TopCoordinate / frame.Texture.Height; frame.BottomCoordinate = BottomCoordinate / frame.Texture.Height; } } frame.RelativeX = RelativeX; frame.RelativeY = RelativeY; #endregion return frame; }
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); } }
public AnimationFrame ToAnimationFrame(string contentManagerName, bool loadTexture, TextureCoordinateType coordinateType) { AnimationFrame frame = new AnimationFrame(); #region Set basic variables frame.TextureName = TextureName; frame.FrameLength = FrameLength; if (loadTexture) { if (mTextureInstance != null) { frame.Texture = mTextureInstance; } // I think we should tolarte frames with a null Texture else if (!string.IsNullOrEmpty(TextureName)) { #if IOS || ANDROID frame.Texture = FlatRedBallServices.Load <Texture2D>(TextureName.ToLowerInvariant(), contentManagerName); #else frame.Texture = FlatRedBallServices.Load <Texture2D>(TextureName, contentManagerName); #endif } //frame.Texture = FlatRedBallServices.Load<Texture2D>(TextureName, contentManagerName); } frame.FlipHorizontal = FlipHorizontal; frame.FlipVertical = FlipVertical; if (coordinateType == TextureCoordinateType.UV) { frame.LeftCoordinate = LeftCoordinate; frame.RightCoordinate = RightCoordinate; frame.TopCoordinate = TopCoordinate; frame.BottomCoordinate = BottomCoordinate; } else if (coordinateType == TextureCoordinateType.Pixel) { // April 16, 2015 // Victor Chelaru // We used to throw this exception, but I don't know why we should, because // the Sprite won't show up, and the problem should be discoverable in tools // without a crash //if (frame.Texture == null) //{ // throw new Exception("The frame must have its texture loaded to use the Pixel coordinate type"); //} if (frame.Texture != null) { frame.LeftCoordinate = LeftCoordinate / frame.Texture.Width; frame.RightCoordinate = RightCoordinate / frame.Texture.Width; frame.TopCoordinate = TopCoordinate / frame.Texture.Height; frame.BottomCoordinate = BottomCoordinate / frame.Texture.Height; } } frame.RelativeX = RelativeX; frame.RelativeY = RelativeY; #endregion return(frame); }
public Gum.Graphics.Animation.AnimationChain ToAnimationChain(string contentManagerName, TimeMeasurementUnit timeMeasurementUnit, TextureCoordinateType coordinateType) { if (!string.IsNullOrEmpty(ParentFile)) { throw new NotImplementedException(); } else { Gum.Graphics.Animation.AnimationChain animationChain = new Gum.Graphics.Animation.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); } }