private void CustomInitialize() { this.YAcceleration = -40; spriteRigSave = SpriteRigSave.FromFile("Content/Entities/Player/ballMan.srgx"); spriteRig = spriteRigSave.ToSpriteRig("Global"); SpriteManager.AddSpriteRig(spriteRig); spriteRig.SetPose(poseChainName, secondsFromTheStart); spriteRig.Animate = true; spriteRig.AnimationSpeed = 3.0f; spriteRig.ScaleBy(0.3f, true); spriteRig.Cycle = true; spriteRig.Root.RelativeRotationZ = 90; }
public static void UnloadStaticContent() { IsStaticContentLoaded = false; mHasRegisteredUnload = false; if (ShapeCollectionFile != null) { ShapeCollectionFile.RemoveFromManagers(ContentManagerName != "Global"); ShapeCollectionFile= null; } if (mech != null) { mech= null; } if (redball != null) { redball= null; } if (ballMan != null) { ballMan.Destroy(); ballMan= null; } }
public static void LoadStaticContent(string contentManagerName) { ContentManagerName = contentManagerName; #if DEBUG if (contentManagerName == FlatRedBallServices.GlobalContentManager) { HasBeenLoadedWithGlobalContentManager = true; } else if (HasBeenLoadedWithGlobalContentManager) { throw new Exception("This type has been loaded with a Global content manager, then loaded with a non-global. This can lead to a lot of bugs"); } #endif if (IsStaticContentLoaded == false) { IsStaticContentLoaded = true; lock (mLockObject) { if (!mHasRegisteredUnload && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("PlayerStaticUnload", UnloadStaticContent); mHasRegisteredUnload = true; } } bool registerUnload = false; if (!FlatRedBallServices.IsLoaded<FlatRedBall.Math.Geometry.ShapeCollection>(@"content/entities/player/shapecollectionfile.shcx", ContentManagerName)) { registerUnload = true; } ShapeCollectionFile = FlatRedBallServices.Load<FlatRedBall.Math.Geometry.ShapeCollection>(@"content/entities/player/shapecollectionfile.shcx", ContentManagerName); if (!FlatRedBallServices.IsLoaded<Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/player/mech.png", ContentManagerName)) { registerUnload = true; } mech = FlatRedBallServices.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/player/mech.png", ContentManagerName); if (!FlatRedBallServices.IsLoaded<Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/player/redball.bmp", ContentManagerName)) { registerUnload = true; } redball = FlatRedBallServices.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/player/redball.bmp", ContentManagerName); if (!FlatRedBallServices.IsLoaded<FlatRedBall.ManagedSpriteGroups.SpriteRig>(@"content/entities/player/ballman.srgx", ContentManagerName)) { registerUnload = true; } ballMan = FlatRedBallServices.Load<FlatRedBall.ManagedSpriteGroups.SpriteRig>(@"content/entities/player/ballman.srgx", ContentManagerName); if (registerUnload && ContentManagerName != FlatRedBallServices.GlobalContentManager) { lock (mLockObject) { if (!mHasRegisteredUnload && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("PlayerStaticUnload", UnloadStaticContent); mHasRegisteredUnload = true; } } } CustomLoadStaticContent(contentManagerName); } }
public static void LoadSpriteRigOk(Window callingWindow) { #region Load the SpriteRig EditorSprite es; string fileName = ((FileWindow)callingWindow).Results[0]; SpriteRigSave srs = SpriteRigSave.FromFile(fileName); SpriteList loadedSprites = new SpriteList(); SpriteRig spriteRig = srs.ToSpriteRig(GameData.SceneContentManager); #endregion #region Play some Pose so that the SpriteRig has a proper pose and texture coordinates // Play and stop an animation to get the texture coordinates set up in case // the SpriteRig has texture coords defined in its AnimationChains if (spriteRig.PoseChains.Count != 0) { spriteRig.SetPoseChain(spriteRig.PoseChains[0]); spriteRig.Animate = true; spriteRig.SetPositionAtTimeFromAnimationStart(0); spriteRig.Animate = false; } #endregion GuiData.srSaveOptions.joints = new SpriteList(); GuiData.srSaveOptions.bodySprites = new SpriteList(); GuiData.srSaveOptions.joints.Clear(); GuiData.srSaveOptions.bodySprites.Clear(); string oldRelativeDirectory = FileManager.RelativeDirectory; FileManager.RelativeDirectory = FileManager.GetDirectory(fileName); foreach (Sprite regularSprite in spriteRig.Joints) { es = new EditorSprite(); es.SetFromRegularSprite(regularSprite); GameData.Scene.Sprites.Add(es); SpriteManager.AddSprite(es); loadedSprites.AddOneWay(es); GuiData.srSaveOptions.joints.Add(es); } foreach (Sprite regularSprite in spriteRig.BodySprites) { es = new EditorSprite(); es.SetFromRegularSprite(regularSprite); GameData.Scene.Sprites.Add(es); SpriteManager.AddSprite(es); loadedSprites.AddOneWay(es); GuiData.srSaveOptions.bodySprites.Add(es); } // The root is not part of the body Sprites, but it should be if (spriteRig.Root != null && GameData.Scene.Sprites.Contains(spriteRig.Root) == false) { es = new EditorSprite(); es.SetFromRegularSprite(spriteRig.Root); GameData.Scene.Sprites.Add(es); SpriteManager.AddSprite(es); loadedSprites.AddOneWay(es); GuiData.srSaveOptions.bodySprites.Add(es); } if (spriteRig.Root != null) { GuiData.srSaveOptions.root = GuiData.srSaveOptions.bodySprites.FindByName(spriteRig.Root.Name); GuiData.srSaveOptions.bodySprites.Remove(GuiData.srSaveOptions.root); } GuiData.srSaveOptions.poseChains = spriteRig.PoseChains; if (srs.JointsVisible) { GuiData.srSaveOptions.jointsVisible.Press(); } else { GuiData.srSaveOptions.jointsVisible.Unpress(); } if (srs.RootVisible) { GuiData.srSaveOptions.rootVisible.Press(); } else { GuiData.srSaveOptions.rootVisible.Unpress(); } FileManager.RelativeDirectory = oldRelativeDirectory; string oldRelative = FileManager.RelativeDirectory; if (srs.AssetsRelativeToFile) { FileManager.RelativeDirectory = FileManager.GetDirectory(fileName); } FileManager.RelativeDirectory = oldRelative; foreach (SpriteSave ss in srs.Joints) { srs.BodySprites.Add(ss); } for (int i = 0; i < loadedSprites.Count; i++) { if (loadedSprites[i].PixelSize > 0f) { ((EditorSprite)loadedSprites[i]).ConstantPixelSizeExempt = false; } else { ((EditorSprite)loadedSprites[i]).ConstantPixelSizeExempt = true; } if (loadedSprites[i].Texture.texture != null) { GuiData.ListWindow.Add(loadedSprites[i].Texture); } string parentName = ""; Sprite matchingSprite = spriteRig.BodySprites.FindByName(loadedSprites[i].Name); if (matchingSprite == null) { matchingSprite = spriteRig.Joints.FindByName(loadedSprites[i].Name); } // parent may be null if there is no root if (matchingSprite != null && matchingSprite.Parent != null) { parentName = matchingSprite.Parent.Name; loadedSprites[i].AttachTo(loadedSprites.FindByName(parentName), false); } } GameData.Scene.Sprites.SortZInsertionDescending(); AskToSearchForReplacements(((FileWindow)callingWindow).Results[0]); }