public static void RenderSprite(Sprite sprite, int leftPixel, int topPixel, int pixelWidth, int pixelHeight, ImageData imageData) { if (sprite.Texture == null || sprite.BlendOperation != BlendOperation.Regular) { // for now throw an exception, later we may want to handle pure color rendering and stuff like that throw new NotImplementedException(); } ImageData spriteTextureImageData = ImageData.FromTexture2D(sprite.Texture); #if FRB_MDX ColorOperation colorOperation = GraphicalEnumerations.TranslateTextureOperationToColorOperation(sprite.ColorOperation); #else ColorOperation colorOperation = sprite.ColorOperation; #endif spriteTextureImageData.ApplyColorOperation(colorOperation, sprite.Red, sprite.Green, sprite.Blue, sprite.Alpha); int rightBound = System.Math.Min(imageData.Width, leftPixel + pixelWidth); int bottomBound = System.Math.Min(imageData.Height, topPixel + pixelHeight); int actualWidth = rightBound - leftPixel; int actualHeight = bottomBound - topPixel; for (int destinationX = leftPixel; destinationX < rightBound; destinationX++) { for (int destinationY = topPixel; destinationY < bottomBound; destinationY++) { int sourcePixelX = spriteTextureImageData.Width * (destinationX - leftPixel) / pixelWidth; int sourcePixelY = spriteTextureImageData.Height * (destinationY - topPixel) / pixelHeight; Color sourcePixel = spriteTextureImageData.GetPixelColor(sourcePixelX, sourcePixelY); if (sourcePixel.A != 255) { Color destinationPixel = imageData.GetPixelColor(destinationX, destinationY); #if FRB_MDX sourcePixel = Color.FromArgb( System.Math.Max(sourcePixel.A, destinationPixel.A), (byte)(destinationPixel.R * (255 - sourcePixel.A) / 255.0f + sourcePixel.R * (sourcePixel.A) / 255.0f), (byte)(destinationPixel.G * (255 - sourcePixel.A) / 255.0f + sourcePixel.G * (sourcePixel.A) / 255.0f), (byte)(destinationPixel.B * (255 - sourcePixel.A) / 255.0f + sourcePixel.B * (sourcePixel.A) / 255.0f)); // This is probably not accurate, but will work currently. Eventually we may want to look at how blending is actually performed #else sourcePixel.R = (byte)(destinationPixel.R * (255 - sourcePixel.A) / 255.0f + sourcePixel.R * (sourcePixel.A) / 255.0f); sourcePixel.G = (byte)(destinationPixel.G * (255 - sourcePixel.A) / 255.0f + sourcePixel.G * (sourcePixel.A) / 255.0f); sourcePixel.B = (byte)(destinationPixel.B * (255 - sourcePixel.A) / 255.0f + sourcePixel.B * (sourcePixel.A) / 255.0f); // This is probably not accurate, but will work currently. Eventually we may want to look at how blending is actually performed sourcePixel.A = System.Math.Max(sourcePixel.A, destinationPixel.A); #endif } imageData.SetPixel(destinationX, destinationY, sourcePixel); } } }
public static TextSave FromText(Text text) { TextSave textSave = new TextSave(); textSave.X = text.Position.X; textSave.Y = text.Position.Y; textSave.Z = text.Position.Z; textSave.RotationX = text.RotationX; textSave.RotationY = text.RotationY; textSave.RotationZ = text.RotationZ; textSave.RelativeX = text.RelativePosition.X; textSave.RelativeY = text.RelativePosition.Y; textSave.RelativeZ = text.RelativePosition.Z; textSave.RelativeRotationX = text.RelativeRotationX; textSave.RelativeRotationY = text.RelativeRotationY; textSave.RelativeRotationZ = text.RelativeRotationZ; textSave.DisplayText = text.DisplayText; textSave.Name = text.Name; textSave.MaxWidth = text.MaxWidth; textSave.MaxWidthBehavior = text.MaxWidthBehavior; textSave.Scale = text.Scale; textSave.Spacing = text.Spacing; textSave.NewLineDistance = text.NewLineDistance; textSave.VerticalAlignment = text.VerticalAlignment; textSave.HorizontalAlignment = text.HorizontalAlignment; textSave.Visible = text.Visible; textSave.CursorSelectable = text.CursorSelectable; if (text.Parent != null) { textSave.Parent = text.Parent.Name; } if (text.Font != null && text.Font != TextManager.DefaultFont) { textSave.FontFile = text.Font.mFontFile; if (text.Font.mTextures.Length == 1) { textSave.FontTexture = text.Font.Texture.Name; } else { textSave.FontTexture = ""; } } #if FRB_MDX //spriteSave.Fade = 255 - spriteToCreateSaveFrom.Alpha; //spriteSave.FadeRate = -spriteToCreateSaveFrom.AlphaRate; textSave.Red = text.Red; textSave.Green = text.Green; textSave.Blue = text.Blue; //spriteSave.TintRedRate = spriteToCreateSaveFrom.RedRate; //spriteSave.TintGreenRate = spriteToCreateSaveFrom.GreenRate; //spriteSave.TintBlueRate = spriteToCreateSaveFrom.BlueRate; textSave.ColorOperation = GraphicalEnumerations.TranslateColorOperation(text.ColorOperation); #elif FRB_XNA //spriteSave.Fade = (1 - spriteToCreateSaveFrom.Alpha) * 255.0f; //spriteSave.FadeRate = -spriteToCreateSaveFrom.AlphaRate * 255.0f; textSave.Red = text.Red * 255.0f; textSave.Green = text.Green * 255.0f; textSave.Blue = text.Blue * 255.0f; //spriteSave.TintRedRate = spriteToCreateSaveFrom.RedRate * 255.0f; //spriteSave.TintGreenRate = spriteToCreateSaveFrom.GreenRate * 255.0f; //spriteSave.TintBlueRate = spriteToCreateSaveFrom.BlueRate * 255.0f; textSave.ColorOperation = GraphicalEnumerations.ColorOperationToFlatRedBallMdxString(text.ColorOperation); #endif return(textSave); }
public Text ToText(string contentManagerName) { Text text = new Text(); text.X = X; text.Y = Y; text.Z = Z; text.RotationX = RotationX; text.RotationY = RotationY; text.RotationZ = RotationZ; text.RelativePosition.X = RelativeX; text.RelativePosition.Y = RelativeY; text.RelativePosition.Z = RelativeZ; text.RelativeRotationX = RelativeRotationX; text.RelativeRotationY = RelativeRotationY; text.RelativeRotationZ = RelativeRotationZ; text.DisplayText = DisplayText; text.Name = Name; text.Scale = Scale; text.Spacing = Spacing; text.NewLineDistance = NewLineDistance; text.MaxWidth = MaxWidth; text.MaxWidthBehavior = MaxWidthBehavior; text.VerticalAlignment = VerticalAlignment; text.HorizontalAlignment = HorizontalAlignment; text.Visible = Visible; text.CursorSelectable = CursorSelectable; #if !SILVERLIGHT #if !MONODROID if (this.mFontTextureInstance != null) { BitmapFont bitmapFont = new BitmapFont( mFontTextureInstance, FontPatternText); text.Font = bitmapFont; } else #endif if (!string.IsNullOrEmpty(FontFile)) { BitmapFont bitmapFont = null; if (!string.IsNullOrEmpty(FontTexture)) { bitmapFont = new BitmapFont( FontTexture, FontFile, contentManagerName); } else { bitmapFont = new BitmapFont( FontFile, contentManagerName); } text.Font = bitmapFont; } else { text.Font = TextManager.DefaultFont; } #endif #if FRB_XNA //valueToDivideBy = 255; #endif //sprite.Alpha = (255 - Fade) / valueToDivideBy; //sprite.AlphaRate = -FadeRate / valueToDivideBy; //sprite.BlendOperation = GraphicalEnumerations.TranslateBlendOperation(BlendOperation); //sprite.RedRate = TintRedRate / valueToDivideBy; //sprite.GreenRate = TintGreenRate / valueToDivideBy; //sprite.BlueRate = TintBlueRate / valueToDivideBy; var colorOperation = ColorOperation; #if MONODROID if (colorOperation == "SelectArg2") { colorOperation = "Modulate"; } #endif GraphicalEnumerations.SetColors(text, Red, Green, Blue, colorOperation); return(text); }
public EmissionSettings ToEmissionSettings(string contentManagerName) { EmissionSettings emissionSettings = new EmissionSettings(); emissionSettings.VelocityRangeType = VelocityRangeType; emissionSettings.RadialVelocity = RadialVelocity; emissionSettings.RadialVelocityRange = RadialVelocityRange; emissionSettings.Billboarded = Billboarded; emissionSettings.XVelocity = XVelocity; emissionSettings.YVelocity = YVelocity; emissionSettings.ZVelocity = ZVelocity; emissionSettings.XVelocityRange = XVelocityRange; emissionSettings.YVelocityRange = YVelocityRange; emissionSettings.ZVelocityRange = ZVelocityRange; emissionSettings.WedgeAngle = WedgeAngle; emissionSettings.WedgeSpread = WedgeSpread; emissionSettings.RotationX = RotationX; emissionSettings.RotationXVelocity = RotationXVelocity; emissionSettings.RotationXRange = RotationXRange; emissionSettings.RotationXVelocityRange = RotationXVelocityRange; emissionSettings.RotationY = RotationY; emissionSettings.RotationYVelocity = RotationYVelocity; emissionSettings.RotationYRange = RotationYRange; emissionSettings.RotationYVelocityRange = RotationYVelocityRange; emissionSettings.RotationZ = RotationZ; emissionSettings.RotationZVelocity = RotationZVelocity; emissionSettings.RotationZRange = RotationZRange; emissionSettings.RotationZVelocityRange = RotationZVelocityRange; emissionSettings.XAcceleration = XAcceleration; emissionSettings.YAcceleration = YAcceleration; emissionSettings.ZAcceleration = ZAcceleration; emissionSettings.XAccelerationRange = XAccelerationRange; emissionSettings.YAccelerationRange = YAccelerationRange; emissionSettings.ZAccelerationRange = ZAccelerationRange; emissionSettings.Drag = Drag; emissionSettings.ScaleX = ScaleX; emissionSettings.ScaleY = ScaleY; emissionSettings.ScaleXRange = ScaleXRange; emissionSettings.ScaleYRange = ScaleYRange; emissionSettings.ScaleXVelocity = ScaleXVelocity; emissionSettings.ScaleYVelocity = ScaleYVelocity; emissionSettings.ScaleXVelocityRange = ScaleXVelocityRange; emissionSettings.ScaleYVelocityRange = ScaleYVelocityRange; emissionSettings.MatchScaleXToY = MatchScaleXToY; if (TextureScale > 0) { emissionSettings.TextureScale = TextureScale; } else { emissionSettings.TextureScale = -1; } #if FRB_MDX float divisionValue = 1; #else float divisionValue = 255; #endif emissionSettings.Alpha = (255 - Fade) / divisionValue; emissionSettings.Red = TintRed / divisionValue; emissionSettings.Green = TintGreen / divisionValue; emissionSettings.Blue = TintBlue / divisionValue; emissionSettings.AlphaRate = -FadeRate / divisionValue; emissionSettings.RedRate = TintRedRate / divisionValue; emissionSettings.BlueRate = TintBlueRate / divisionValue; emissionSettings.GreenRate = TintGreenRate / divisionValue; emissionSettings.BlendOperation = GraphicalEnumerations.TranslateBlendOperation(BlendOperation); emissionSettings.ColorOperation = GraphicalEnumerations.TranslateColorOperation(ColorOperation); emissionSettings.Animate = Animate; emissionSettings.CurrentChainName = CurrentChainName; // load the animation chains or the texture but not both // chains take priority over texture? if (!string.IsNullOrEmpty(AnimationChains)) { // load the animation chain, note that this could throw an exception if file names are bad or chain doesn't exist! emissionSettings.AnimationChains = FlatRedBallServices.Load <AnimationChainList>(AnimationChains, contentManagerName); if (!string.IsNullOrEmpty(CurrentChainName)) { emissionSettings.AnimationChain = emissionSettings.AnimationChains[emissionSettings.CurrentChainName]; } } else { if (!string.IsNullOrEmpty(Texture)) { // load the texture, emissionSettings.Texture = FlatRedBallServices.Load <Texture2D>(Texture, contentManagerName); } } if (Instructions != null) { emissionSettings.Instructions = Instructions.ToInstructionBlueprintList(); foreach (InstructionBlueprint blueprint in emissionSettings.Instructions) { if (GraphicalEnumerations.ConvertableSpriteProperties.Contains(blueprint.MemberName)) { blueprint.MemberValue = (float)blueprint.MemberValue / divisionValue; } //if(blueprint.MemberName.Equals("Alpha")){ //} //else if(blueprint.MemberName.Equals("AlphaRate")){ //} //else if(blueprint.MemberName.Equals("Blue")){ //} //else if(blueprint.MemberName.Equals("BlueRate")){ //} //else if(blueprint.MemberName.Equals("Green")){ //} //else if(blueprint.MemberName.Equals("GreenRate")){ //} //else if(blueprint.MemberName.Equals("Red")){ //} //else if(blueprint.MemberName.Equals("RedRate")){ //} } } // TODO: Add support for saving AnimationChains. Probably need to change the mAnimation // field from an AnimationChain to an AnimationChainSave return(emissionSettings); }
public static EmissionSettingsSave FromEmissionSettings(EmissionSettings emissionSettings) { EmissionSettingsSave emissionSettingsSave = new EmissionSettingsSave(); emissionSettingsSave.mVelocityRangeType = emissionSettings.VelocityRangeType; emissionSettingsSave.mRadialVelocity = emissionSettings.RadialVelocity; emissionSettingsSave.mRadialVelocityRange = emissionSettings.RadialVelocityRange; emissionSettingsSave.mXVelocity = emissionSettings.XVelocity; emissionSettingsSave.mYVelocity = emissionSettings.YVelocity; emissionSettingsSave.mZVelocity = emissionSettings.ZVelocity; emissionSettingsSave.mXVelocityRange = emissionSettings.XVelocityRange; emissionSettingsSave.mYVelocityRange = emissionSettings.YVelocityRange; emissionSettingsSave.mZVelocityRange = emissionSettings.ZVelocityRange; emissionSettingsSave.mWedgeAngle = emissionSettings.WedgeAngle; emissionSettingsSave.mWedgeSpread = emissionSettings.WedgeSpread; emissionSettingsSave.Billboarded = emissionSettings.Billboarded; emissionSettingsSave.mRotationX = emissionSettings.RotationX; emissionSettingsSave.mRotationXVelocity = emissionSettings.RotationXVelocity; emissionSettingsSave.mRotationXRange = emissionSettings.RotationXRange; emissionSettingsSave.mRotationXVelocityRange = emissionSettings.RotationXVelocityRange; emissionSettingsSave.mRotationY = emissionSettings.RotationY; emissionSettingsSave.mRotationYVelocity = emissionSettings.RotationYVelocity; emissionSettingsSave.mRotationYRange = emissionSettings.RotationYRange; emissionSettingsSave.mRotationYVelocityRange = emissionSettings.RotationYVelocityRange; emissionSettingsSave.mRotationZ = emissionSettings.RotationZ; emissionSettingsSave.mRotationZVelocity = emissionSettings.RotationZVelocity; emissionSettingsSave.mRotationZRange = emissionSettings.RotationZRange; emissionSettingsSave.mRotationZVelocityRange = emissionSettings.RotationZVelocityRange; emissionSettingsSave.mXAcceleration = emissionSettings.XAcceleration; emissionSettingsSave.mYAcceleration = emissionSettings.YAcceleration; emissionSettingsSave.mZAcceleration = emissionSettings.ZAcceleration; emissionSettingsSave.mXAccelerationRange = emissionSettings.XAccelerationRange; emissionSettingsSave.mYAccelerationRange = emissionSettings.YAccelerationRange; emissionSettingsSave.mZAccelerationRange = emissionSettings.ZAccelerationRange; emissionSettingsSave.mScaleX = emissionSettings.ScaleX; emissionSettingsSave.mScaleY = emissionSettings.ScaleY; emissionSettingsSave.mScaleXRange = emissionSettings.ScaleXRange; emissionSettingsSave.mScaleYRange = emissionSettings.ScaleYRange; emissionSettingsSave.mMatchScaleXToY = emissionSettings.MatchScaleXToY; emissionSettingsSave.mScaleXVelocity = emissionSettings.ScaleXVelocity; emissionSettingsSave.mScaleYVelocity = emissionSettings.ScaleYVelocity; emissionSettingsSave.mScaleXVelocityRange = emissionSettings.ScaleXVelocityRange; emissionSettingsSave.mScaleYVelocityRange = emissionSettings.ScaleYVelocityRange; if (emissionSettings.TextureScale > 0) { emissionSettingsSave.TextureScale = emissionSettings.TextureScale; } else { emissionSettingsSave.TextureScale = -1; } int multiple = 255; emissionSettingsSave.mFade = (1 - emissionSettings.Alpha) * 255; emissionSettingsSave.mTintRed = emissionSettings.Red * 255; emissionSettingsSave.mTintGreen = emissionSettings.Green * 255; emissionSettingsSave.mTintBlue = emissionSettings.Blue * 255; emissionSettingsSave.mFadeRate = -emissionSettings.AlphaRate * 255; emissionSettingsSave.mTintRedRate = emissionSettings.RedRate * 255; emissionSettingsSave.mTintGreenRate = emissionSettings.GreenRate * 255; emissionSettingsSave.mTintBlueRate = emissionSettings.BlueRate * 255; emissionSettingsSave.mBlendOperation = GraphicalEnumerations.BlendOperationToFlatRedBallMdxString(emissionSettings.BlendOperation); emissionSettingsSave.mColorOperation = GraphicalEnumerations.ColorOperationToFlatRedBallMdxString( emissionSettings.ColorOperation); // preserve animation and texture settings emissionSettingsSave.mAnimate = emissionSettings.Animate; // TODO: Justin - not sure if we need to force relative here? emissionSettingsSave.AnimationChains = emissionSettings.AnimationChains.Name; emissionSettingsSave.CurrentChainName = emissionSettings.CurrentChainName; // TODO: Justin - not sure if we neet to force relative here? emissionSettingsSave.Texture = emissionSettings.Texture.Name; emissionSettingsSave.Instructions = InstructionBlueprintListSave.FromInstructionBlueprintList(emissionSettings.Instructions); foreach (InstructionSave blueprint in emissionSettingsSave.Instructions.Instructions) { if (GraphicalEnumerations.ConvertableSpriteProperties.Contains(blueprint.Member)) { blueprint.Value = (float)blueprint.Value * multiple; } } emissionSettingsSave.mDrag = emissionSettings.Drag; return(emissionSettingsSave); }
public void SetSprite(string contentManagerName, Sprite sprite, bool setTextures) { // Set Texture and PixelSize BEFORE setting Scale so that the Scale // overrides it if it's different. if (setTextures) { #if !MONODROID if (mTextureInstance != null) { sprite.Texture = mTextureInstance; } else #endif // Sprites can have NULL textures as of April 18, 2009 if (!string.IsNullOrEmpty(Texture)) { sprite.Texture = FlatRedBallServices.Load <Texture2D>(Texture, contentManagerName); } } sprite.X = X; sprite.Y = Y; sprite.Z = Z; sprite.RotationX = RotationX; sprite.RotationY = RotationY; sprite.RotationZ = RotationZ; sprite.RotationZVelocity = RotationZVelocity; sprite.PixelSize = ConstantPixelSize; sprite.TopTextureCoordinate = TopTextureCoordinate; sprite.BottomTextureCoordinate = BottomTextureCoordinate; sprite.LeftTextureCoordinate = LeftTextureCoordinate; sprite.RightTextureCoordinate = RightTextureCoordinate; // End of stuff to set before setting Scale sprite.ScaleX = ScaleX; sprite.ScaleXVelocity = ScaleXVelocity; sprite.ScaleY = ScaleY; sprite.ScaleYVelocity = ScaleYVelocity; sprite.XVelocity = XVelocity; sprite.YVelocity = YVelocity; sprite.ZVelocity = ZVelocity; sprite.XAcceleration = XAcceleration; sprite.YAcceleration = YAcceleration; sprite.ZAcceleration = ZAcceleration; sprite.RelativeX = RelativeX; sprite.RelativeY = RelativeY; sprite.RelativeZ = RelativeZ; sprite.RelativeRotationX = RelativeRotationX; sprite.RelativeRotationY = RelativeRotationY; sprite.RelativeRotationZ = RelativeRotationZ; sprite.Name = Name; sprite.Animate = Animate; if (setTextures) { SetRuntimeAnimationChain(contentManagerName, sprite, #if !MONODROID mAnimationChainListInstance, #else null, #endif CurrentChain, AnimationChains, AnimationChainsFile ); } float valueToDivideBy = 255 / GraphicalEnumerations.MaxColorComponentValue; sprite.Alpha = (255 - Fade) / valueToDivideBy; sprite.AlphaRate = -FadeRate / valueToDivideBy; sprite.BlendOperation = GraphicalEnumerations.TranslateBlendOperation(BlendOperation); sprite.RedRate = TintRedRate / valueToDivideBy; sprite.GreenRate = TintGreenRate / valueToDivideBy; sprite.BlueRate = TintBlueRate / valueToDivideBy; GraphicalEnumerations.SetColors(sprite, TintRed, TintGreen, TintBlue, ColorOperation); // If the Texture is null, we may want to use "Color" instead of "ColorTextureAlpha" if (sprite.Texture == null && sprite.ColorOperation == FlatRedBall.Graphics.ColorOperation.ColorTextureAlpha) { sprite.ColorOperation = FlatRedBall.Graphics.ColorOperation.Color; } sprite.mOrdered = Ordered; sprite.Visible = Visible; sprite.TextureAddressMode = TextureAddressMode; sprite.FlipHorizontal = FlipHorizontal; sprite.FlipVertical = FlipVertical; }
public void SetFrom <T>(T spriteToCreateSaveFrom) where T : PositionedObject, IColorable, ICursorSelectable, IReadOnlyScalable, IAnimationChainAnimatable { X = spriteToCreateSaveFrom.X; Y = spriteToCreateSaveFrom.Y; // Coordinates will be inverted depending on the CoordinateSystem // when the scene is loaded. Z = spriteToCreateSaveFrom.Z; RotationX = spriteToCreateSaveFrom.RotationX; RotationY = spriteToCreateSaveFrom.RotationY; RotationZ = spriteToCreateSaveFrom.RotationZ; RotationZVelocity = spriteToCreateSaveFrom.RotationZVelocity; ScaleX = spriteToCreateSaveFrom.ScaleX; ScaleY = spriteToCreateSaveFrom.ScaleY; if (spriteToCreateSaveFrom is IScalable) { ScaleXVelocity = ((IScalable)(spriteToCreateSaveFrom)).ScaleXVelocity; ScaleYVelocity = ((IScalable)(spriteToCreateSaveFrom)).ScaleYVelocity; } XVelocity = spriteToCreateSaveFrom.XVelocity; YVelocity = spriteToCreateSaveFrom.YVelocity; ZVelocity = spriteToCreateSaveFrom.ZVelocity; XAcceleration = spriteToCreateSaveFrom.XAcceleration; YAcceleration = spriteToCreateSaveFrom.YAcceleration; ZAcceleration = spriteToCreateSaveFrom.ZAcceleration; RelativeX = spriteToCreateSaveFrom.RelativeX; RelativeY = spriteToCreateSaveFrom.RelativeY; RelativeZ = spriteToCreateSaveFrom.RelativeZ; RelativeRotationX = spriteToCreateSaveFrom.RelativeRotationX; RelativeRotationY = spriteToCreateSaveFrom.RelativeRotationY; RelativeRotationZ = spriteToCreateSaveFrom.RelativeRotationZ; if (spriteToCreateSaveFrom.Name != null) { Name = spriteToCreateSaveFrom.Name; } Animate = spriteToCreateSaveFrom.Animate; if (spriteToCreateSaveFrom.CurrentChain == null) { CurrentChain = -1; } else { CurrentChain = spriteToCreateSaveFrom.CurrentChain.IndexInLoadedAchx; // It's possible that the chain is just a GIF. In that case, it would have a -1 index // in the loaded Achx. But we still want this thing to play, so we'll just assume an index // of 0 if (CurrentChain == -1) { CurrentChain = 0; } } if (spriteToCreateSaveFrom.AnimationChains != null) { if (string.IsNullOrEmpty(spriteToCreateSaveFrom.AnimationChains.Name) && spriteToCreateSaveFrom.AnimationChains.Count != 0) { if (!string.IsNullOrEmpty(spriteToCreateSaveFrom.AnimationChains[0].ParentAchxFileName)) { AnimationChainsFile = spriteToCreateSaveFrom.AnimationChains[0].ParentAchxFileName; } else { AnimationChainsFile = spriteToCreateSaveFrom.AnimationChains[0].ParentGifFileName; } } else { AnimationChainsFile = spriteToCreateSaveFrom.AnimationChains.Name; } } if (spriteToCreateSaveFrom.Parent != null) { Parent = spriteToCreateSaveFrom.Parent.Name; } BlendOperation = GraphicalEnumerations.BlendOperationToFlatRedBallMdxString(spriteToCreateSaveFrom.BlendOperation); Fade = (1 - spriteToCreateSaveFrom.Alpha) * 255.0f; FadeRate = -spriteToCreateSaveFrom.AlphaRate * 255.0f; TintRed = spriteToCreateSaveFrom.Red * 255.0f; TintGreen = spriteToCreateSaveFrom.Green * 255.0f; TintBlue = spriteToCreateSaveFrom.Blue * 255.0f; TintRedRate = spriteToCreateSaveFrom.RedRate * 255.0f; TintGreenRate = spriteToCreateSaveFrom.GreenRate * 255.0f; TintBlueRate = spriteToCreateSaveFrom.BlueRate * 255.0f; ColorOperation = GraphicalEnumerations.ColorOperationToFlatRedBallMdxString(spriteToCreateSaveFrom.ColorOperation); if (spriteToCreateSaveFrom is Sprite) { Sprite asSprite = spriteToCreateSaveFrom as Sprite; Visible = asSprite.Visible; if (asSprite.Texture != null) { // Vic says: On November 11, 2009 I found an interesting // bug. I was working on the TileEditor which created a Scene // that contained animated Sprites. These Sprites used an AnimationChain // that was created by loading a .GIF. That means that each individual texture // in the AnimationChain is not its own file, but rather a Texture created from the // GIF. This means that the Name of the Texture is not a valid Name. // But this makes me think - if a Sprite has an AnimationChain and it's currently Animated, // why do we even need to save off the Texture? Instead, let's just not save it at all. This // will save a little bit of space and could also prevent some loading-related bugs. if (string.IsNullOrEmpty(AnimationChainsFile) || (asSprite.CurrentChain == null || !asSprite.Animate)) { Texture = asSprite.Texture.SourceFile(); } } ConstantPixelSize = asSprite.PixelSize; TopTextureCoordinate = asSprite.TopTextureCoordinate; BottomTextureCoordinate = asSprite.BottomTextureCoordinate; LeftTextureCoordinate = asSprite.LeftTextureCoordinate; RightTextureCoordinate = asSprite.RightTextureCoordinate; FlipHorizontal = asSprite.FlipHorizontal; FlipVertical = asSprite.FlipVertical; TextureAddressMode = asSprite.TextureAddressMode; // If the Sprite is not part of the ZBufferedSprites, then it's ordered. Ordered = !asSprite.ListsBelongingTo.Contains(SpriteManager.mZBufferedSprites); } else if (spriteToCreateSaveFrom is FlatRedBall.ManagedSpriteGroups.SpriteFrame) { FlatRedBall.ManagedSpriteGroups.SpriteFrame asSpriteFrame = spriteToCreateSaveFrom as FlatRedBall.ManagedSpriteGroups.SpriteFrame; Visible = asSpriteFrame.Visible; Texture = asSpriteFrame.Texture.Name; } }
public FlatRedBall.ManagedSpriteGroups.SpriteFrame ToSpriteFrame(string contentManagerName) { Texture2D textureToUse = null; #if !MONODROID if (ParentSprite.mTextureInstance != null) { textureToUse = ParentSprite.mTextureInstance; } else { #endif textureToUse = FlatRedBallServices.Load <Texture2D>(ParentSprite.Texture, contentManagerName); #if !MONODROID } #endif FlatRedBall.ManagedSpriteGroups.SpriteFrame spriteFrame = new FlatRedBall.ManagedSpriteGroups.SpriteFrame( textureToUse, (FlatRedBall.ManagedSpriteGroups.SpriteFrame.BorderSides)BorderSides); spriteFrame.Name = ParentSprite.Name; spriteFrame.Position = new Vector3( ParentSprite.X, ParentSprite.Y, ParentSprite.Z); spriteFrame.RelativePosition = new Vector3( ParentSprite.RelativeX, ParentSprite.RelativeY, ParentSprite.RelativeZ); spriteFrame.RotationX = ParentSprite.RotationX; spriteFrame.RotationY = ParentSprite.RotationY; spriteFrame.RotationZ = ParentSprite.RotationZ; spriteFrame.RelativeRotationX = ParentSprite.RelativeRotationX; spriteFrame.RelativeRotationY = ParentSprite.RelativeRotationY; spriteFrame.RelativeRotationZ = ParentSprite.RelativeRotationZ; spriteFrame.ScaleX = ParentSprite.ScaleX; spriteFrame.ScaleY = ParentSprite.ScaleY; spriteFrame.TextureBorderWidth = TextureBorderWidth; spriteFrame.SpriteBorderWidth = SpriteBorderWidth; spriteFrame.Visible = ParentSprite.Visible; spriteFrame.Animate = ParentSprite.Animate; SpriteSave.SetRuntimeAnimationChain( contentManagerName, spriteFrame, #if !MONODROID ParentSprite.mAnimationChainListInstance, #else null, #endif ParentSprite.CurrentChain, ParentSprite.AnimationChains, ParentSprite.AnimationChainsFile); float valueToDivideBy = 255 / GraphicalEnumerations.MaxColorComponentValue; spriteFrame.Red = ParentSprite.TintRed / valueToDivideBy; spriteFrame.Green = ParentSprite.TintGreen / valueToDivideBy; spriteFrame.Blue = ParentSprite.TintBlue / valueToDivideBy; spriteFrame.Alpha = (255 - ParentSprite.Fade) / valueToDivideBy; spriteFrame.BlendOperation = GraphicalEnumerations.TranslateBlendOperation(ParentSprite.BlendOperation); GraphicalEnumerations.SetColors(spriteFrame, ParentSprite.TintRed, ParentSprite.TintGreen, ParentSprite.TintBlue, ParentSprite.ColorOperation); if (spriteFrame.CenterSprite != null) { spriteFrame.CenterSprite.mOrdered = ParentSprite.Ordered; } return(spriteFrame); }