private void CreateSprites <SpriteType>(string contentManagerName, FlatRedBall.Scene scene, SceneSettingOptions options) where SpriteType : Sprite, new() { bool hasFlag = (options & SceneSettingOptions.ConvertZSeparatedSpritesIntoSpriteGrids) == SceneSettingOptions.ConvertZSeparatedSpritesIntoSpriteGrids; if (!hasFlag) { // Create the Sprites foreach (SpriteSave spriteSave in SpriteList) { Sprite newSprite = null; newSprite = spriteSave.ToSprite <SpriteType>(contentManagerName); scene.Sprites.Add(newSprite); } // Attach the Sprites foreach (SpriteSave spriteSave in SpriteList) { if (string.IsNullOrEmpty(spriteSave.Parent) == false) { scene.Sprites.FindByName(spriteSave.Name).AttachTo( scene.Sprites.FindByName(spriteSave.Parent), false); } } } }
private void AddSpriteGridsToScene(string contentManagerName, FlatRedBall.Scene scene, SceneSettingOptions options) { foreach (SpriteGridSave spriteGridSave in SpriteGridList) { // for now just use the default camera and create a new Random - not sure if user ever needs // to specify the Random to use - perhaps for multiplayer games and SpriteGrids which are using AnimationChains FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid = spriteGridSave.ToSpriteGrid( SpriteManager.Camera, contentManagerName); scene.SpriteGrids.Add(spriteGrid); } bool hasFlag = (options & SceneSettingOptions.ConvertZSeparatedSpritesIntoSpriteGrids) == SceneSettingOptions.ConvertZSeparatedSpritesIntoSpriteGrids; if (hasFlag) { Dictionary <int, FlatRedBall.ManagedSpriteGroups.SpriteGrid> spriteGrids = new Dictionary <int, FlatRedBall.ManagedSpriteGroups.SpriteGrid>(); foreach (SpriteSave spriteSave in this.SpriteList) { FloatRectangle floatRectangle = new FloatRectangle(); int zAsInt = MathFunctions.RoundToInt(spriteSave.Z); if (spriteGrids.ContainsKey(zAsInt) == false) { var newGrid = new ManagedSpriteGroups.SpriteGrid(SpriteManager.Camera, ManagedSpriteGroups.SpriteGrid.Plane.XY, spriteSave.ToSprite(contentManagerName)); spriteGrids.Add(zAsInt, newGrid); scene.SpriteGrids.Add(newGrid); } var spriteGrid = spriteGrids[zAsInt]; spriteGrid.XLeftBound = System.Math.Min(spriteGrid.XLeftBound, spriteSave.X - spriteSave.ScaleX * 2); spriteGrid.YBottomBound = System.Math.Min(spriteGrid.YBottomBound, spriteSave.Y - spriteSave.ScaleY * 2); spriteGrid.XRightBound = System.Math.Max(spriteGrid.XRightBound, spriteSave.X + spriteSave.ScaleX * 2); spriteGrid.YTopBound = System.Math.Max(spriteGrid.YTopBound, spriteSave.Y + spriteSave.ScaleY * 2); spriteGrid.PaintSprite(spriteSave.X, spriteSave.Y, spriteSave.Z, FlatRedBallServices.Load <Texture2D>(spriteSave.Texture)); floatRectangle.Left = spriteSave.LeftTextureCoordinate; floatRectangle.Right = spriteSave.RightTextureCoordinate; floatRectangle.Top = spriteSave.TopTextureCoordinate; floatRectangle.Bottom = spriteSave.BottomTextureCoordinate; spriteGrid.PaintSpriteDisplayRegion(spriteSave.X, spriteSave.Y, spriteSave.Z, ref floatRectangle); } } }
public void SetScene <SpriteType>(string contentManagerName, FlatRedBall.Scene scene, SceneSettingOptions options) where SpriteType : Sprite, new() { #region Set the FileManager.RelativeDirectory if necessary string oldRelativeDirectory = FileManager.RelativeDirectory; if (AssetsRelativeToSceneFile && mSceneDirectory != null) { FileManager.RelativeDirectory = mSceneDirectory; } #endregion CreateSprites <SpriteType>(contentManagerName, scene, options); AddSpriteGridsToScene(contentManagerName, scene, options); #region Create the SpriteFrames foreach (SpriteFrameSave spriteFrameSave in SpriteFrameSaveList) { FlatRedBall.ManagedSpriteGroups.SpriteFrame spriteFrame = spriteFrameSave.ToSpriteFrame(contentManagerName); scene.SpriteFrames.Add(spriteFrame); } // TODO: Attach the SpriteFrames #endregion #region Create the Texts foreach (TextSave textSave in TextSaveList) { Text text = textSave.ToText(contentManagerName); scene.Texts.Add(text); } #endregion #region Invert Z if necessary #if FRB_MDX if (CoordinateSystem == FlatRedBall.Math.CoordinateSystem.RightHanded) { scene.InvertHandedness(); } #else if (CoordinateSystem == FlatRedBall.Math.CoordinateSystem.LeftHanded) { scene.InvertHandedness(); } #endif #endregion FileManager.RelativeDirectory = oldRelativeDirectory; // Set the name of the scene to the file name // Vic says - not sure why this is being made relative. // It should be like a Texture - storing its full path name so it // can be re-saved easily. //if (!(string.IsNullOrEmpty(mFileName))) //asdffdsa // scene.Name = FileManager.RemovePath(this.mFileName); scene.Name = this.mFileName; }