public new void Dispose() { clearObjects(); if (canyon != null) { canyon.Dispose(); } components.Remove(canyon); if (player != null) { player.Dispose(); } components.Remove(player); if (freeCamera != null) { freeCamera.Dispose(); } components.Remove(freeCamera); if (sky != null) { sky.Dispose(); } components.Remove(sky); base.Dispose(); }
public void ComponentRemovedEventTest() { bool fired = false; components.ComponentRemoved += delegate(object sender, GameComponentCollectionEventArgs args) { fired = true; }; MyComponent c = new MyComponent(game); components.Add(c); components.Remove(c); Assert.IsTrue(fired, "ComponentRemoved event did not fire."); }
internal static void ReplaceComponent <T>( this GameComponentCollection components, T toBeReplaced, T replacement ) where T : IGameComponent { components.Remove(toBeReplaced); components.Add(replacement); }
public void RemoveChild(GameComponent component) { if (component is VisualComponent) { ((VisualComponent)component).Remove(); } components.Remove(component); Game.Components.Remove(component); }
protected override void OnLeaving() { var tempComponents = new IGameComponent[_subComponents.Count]; _subComponents.CopyTo(tempComponents, 0); foreach (IGameComponent tempComponent in tempComponents) { _subComponents.Remove(tempComponent); _mainComponents.Remove(tempComponent); } }
public static void Remove(this GameComponentCollection components, object component) { if (component == null) { throw new ArgumentNullException("component"); } var item = components.FirstOrDefault(c => (c is GameComponentAdapter) && ((GameComponentAdapter)c).InnerComponent == component); if (item != null) { components.Remove(item); } }
public void Reset() { if (welcomeSound != null) { welcomeSound.Stop(); } //components.Remove(profil); profil = null; components.Remove(chooser); if (chooser != null) { chooser.Dispose(); } chooser = null; components.Remove(intro); if (intro != null) { intro.Dispose(); } intro = null; components.Remove(credits); if (credits != null) { credits.Dispose(); } credits = null; components.Remove(menu); menu = null; components.Remove(level); level = null; components.Remove(hud); hud = null; components.Remove(console); console = null; components.Clear(); if (game.World != null) { //components.Remove(game.World); game.World.Dispose(); game.World = null; } /* * if (score != null) * { * score.Reset(); * } * score = null;*/ Material.ClearSharedPool(); }
/// <summary> /// When a componenet removed from the game, it will be also removed from the screen. /// </summary> /// <param name="i_Sender">Sender object.</param> /// <param name="i_ArgsHolder">Arguments holder.</param> private void components_ComponentRemoved(object i_Sender, GameComponentCollectionEventArgs i_ArgsHolder) { IGameComponent component = i_ArgsHolder.GameComponent; if (!m_constGameComponentCollection.Contains(component)) { if (m_gameComponentCollection.Contains(component)) { m_gameComponentCollection.Remove(component); } if (m_gameDrawableComponentCollection.Contains(component)) { m_gameDrawableComponentCollection.Remove(component); } if (ComponentRemoved != null) { ComponentRemoved.Invoke(component); } } }
public void Remove(SceneEntity obj) { collection.Remove(obj); }
public override void Update(GameTime gameTime) { Core.UpdateInput(); lastKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(); if (mouseEnabled || SosEngine.Core.Debug) { currentMouseState = Mouse.GetState(); mouseX = (int)(Core.RenderWidth / (float)Game.GraphicsDevice.Viewport.Bounds.Width * currentMouseState.X); mouseY = (int)(Core.RenderHeight / (float)Game.GraphicsDevice.Viewport.Bounds.Height * currentMouseState.Y); if (mouseEnabled) { mouseCursor.Position = new Vector2(mouseX, mouseY); mouseCursor.SetState(currentMouseState.LeftButton == ButtonState.Pressed); } leftMouseButtonClicked = currentMouseState.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed; rightMouseButtonClicked = currentMouseState.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed; middleMouseButtonClicked = currentMouseState.MiddleButton == ButtonState.Released && lastMouseState.MiddleButton == ButtonState.Pressed; leftMouseButtonJustPressed = currentMouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released; dragging = currentMouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Pressed; mouseDelta = new Vector2(mouseX, mouseY) - new Vector2(lastMouseX, lastMouseY); lastMouseX = mouseX; lastMouseY = mouseY; lastMouseState = currentMouseState; } // Update tasks bool anyUpdatedTask = false; for (int i = 0; i < tasks.Count; i++) { if (!tasks[i].IsFinished) { tasks[i].Update(gameTime); anyUpdatedTask = true; } } // Remove finished tasks if (anyUpdatedTask) { tasks.RemoveAll(task => task.IsFinished); } // Update game components foreach (GameComponent component in gameComponents) { component.Update(gameTime); } // Remove game components foreach (GameComponent component in gameComponentsToRemove) { gameComponents.Remove(component); } gameComponentsToRemove.Clear(); if (SosEngine.Core.Debug) { highlighedSprites.Clear(); foreach (GameComponent component in gameComponents) { if (component is SosEngine.Sprite) { if (((SosEngine.Sprite)component).BoundingBoxWithOffset.Contains(mouseX, mouseY)) { highlighedSprites.Add((SosEngine.Sprite)component); } } } if (leftMouseButtonJustPressed && highlighedSprites.Count > 0) { draggedObject = highlighedSprites[0]; } else if (dragging && draggedObject != null) { draggedObject.Position += mouseDelta; if (currentKeyboardState.IsKeyDown(Keys.LeftControl)) { int snappedX = (int)Math.Round(draggedObject.Position.X) / 8 * 8; int snappedY = (int)Math.Round(draggedObject.Position.Y) / 8 * 8; draggedObject.Position = new Vector2(snappedX, snappedY); } SosEngine.Core.Log(string.Format("Position of object is X: {0} Y: {1}", draggedObject.Position.X, draggedObject.Position.Y)); } else { draggedObject = null; } } base.Update(gameTime); }