/// <summary> /// Load graphics content for the game. /// </summary> public override void LoadContent() { if (_content == null) _content = new ContentManager(ScreenManager.Game.Services, "Content"); _components = ScreenManager.Game.Components; _graphicsDevice = ScreenManager.GraphicsDevice; _gameFont = _content.Load<SpriteFont>(@"Fonts\GameFont"); blank = new Texture2D(_graphicsDevice, 1, 1); blank.SetData(new[] { Color.White }); gridTexture = _content.Load<Texture2D>(@"Textures\Grid"); Vector2 viewSize = new Vector2(_graphicsDevice.Viewport.Width, _graphicsDevice.Viewport.Height); _world = new World(_content.Load<Map>(@"Maps\1experiment"), viewSize); _cameraManager = new CameraManager(ScreenManager.Game, _world.Camera, InputType.Keyboard, PlayerIndex.One); _components.Add(_cameraManager); // find the "Box" and "Point" objects we made in the level /*MapObjectLayer objects = _world.Map.GetLayer("Objects") as MapObjectLayer; point = objects.GetObject("Point"); box = objects.GetObject("Box");*/ // attempt to read the box color from the box object properties /*try { boxColor.R = (byte)box.Properties["R"]; boxColor.G = (byte)box.Properties["G"]; boxColor.B = (byte)box.Properties["B"]; boxColor.A = 255; } catch { // on failure, default to yellow boxColor = Color.Yellow; }*/ // A real game would probably have more content than this sample, so // it would take longer to load. We simulate that by delaying for a // while, giving you a chance to admire the beautiful loading screen. //Thread.Sleep(1000); // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); }
/// <summary> /// Load graphics content for the game. /// </summary> public override void LoadContent() { if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); spriteBatch = ScreenManager.SpriteBatch; gameFont = content.Load<SpriteFont>("gamefont"); world = new World(ScreenManager.Game); world.LoadContent(); moveLeftBtn = new ClickableRectangle(ScreenManager.Game, new Rectangle(0, 320, 160, 160), buttonType.MOVE_LEFT); moveRightBtn = new ClickableRectangle(ScreenManager.Game, new Rectangle(640, 320, 160, 160), buttonType.MOVE_RIGHT); jumpBtn = new ClickableRectangle(ScreenManager.Game, new Rectangle(0, 159, 160, 160), buttonType.JUMP); abilityBtn = new ClickableRectangle(ScreenManager.Game, new Rectangle(640, 159, 160, 160), buttonType.SPECIAL_ATTACK); buttons.Add(moveLeftBtn); buttons.Add(moveRightBtn); buttons.Add(jumpBtn); buttons.Add(abilityBtn); p1s = new PlayerInControlBtn(ScreenManager.Game, new Point(200, 0), PlayerSelection.P1); p2s = new PlayerInControlBtn(ScreenManager.Game, new Point(400, 0), PlayerSelection.P2); p3s = new PlayerInControlBtn(ScreenManager.Game, new Point(600, 0), PlayerSelection.P3); buttons.Add(p1s); buttons.Add(p2s); buttons.Add(p3s); PlayerGreen p1 = new PlayerGreen(ScreenManager.Game, new Point(100, 100), gravity); PlayerBlue p2 = new PlayerBlue(ScreenManager.Game, new Point(100, 200), gravity); PlayerRed p3 = new PlayerRed(ScreenManager.Game, new Point(100, 300), gravity); currentPlayerIndex = 0; players.Add(p1); players.Add(p2); players.Add(p3); gameObjects.Add(p1); gameObjects.Add(p2); gameObjects.Add(p3); cam = new Camera(ScreenManager.GraphicsDevice.Viewport); cam.activePlayer = players[currentPlayerIndex]; foreach (GameObject gameObject in gameObjects) { gameObject.LoadContent(); } foreach (GameObject button in buttons) { button.LoadContent(); } // A real game would probably have more content than this sample, so // it would take longer to load. We simulate that by delaying for a // while, giving you a chance to admire the beautiful loading screen. //Thread.Sleep(1000); // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); }
/// <summary> /// Load graphics content for the game. /// </summary> public override void LoadContent() { if (content == null) { content = new ContentManager(ScreenManager.Game.Services, "Content"); } collisionMananger = new CollisionManager(ScreenManager.Game); // Adds collision manager to Game.Service, This Service unloads when UnloadContent is called. ScreenManager.Game.Services.AddService(typeof(ICollisionService), collisionMananger); spriteBatch = ScreenManager.SpriteBatch; gameFont = content.Load<SpriteFont>("gamefont"); //Add game world world = new World(ScreenManager.Game); world.LoadContent(); gameObjects.AddRange(world.tiles); //Add Trigger objects gameObjects.AddRange(world.triggerTile); //Add Destroyable Tile objects foreach (Trigger triggerObj in world.triggerTile) { gameObjects.Add(triggerObj.GetDestroyableTile()); } soundManager = new Sound(ScreenManager.Game); soundManager.LoadContent(); soundManager.PlayMusic("main"); //Adds GUI buttons gamePlayButtons = new GamePlayButtons(ScreenManager.Game); //Add players playerManager = new PlayerManager(ScreenManager.Game, gravity); playerManager.LoadContent(); gameObjects.AddRange(playerManager.players); endPicture = content.Load<Texture2D>("endpicture"); //Add game cam cam = new Camera(ScreenManager.GraphicsDevice.Viewport); cam.activePlayer = playerManager.currentPlayer; // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); GC.Collect(); //Requesting garbage collect }