public void RemoveVisualObject(VisualObject vo) { vo.Visible = false; vo.Enabled = false; vo.UnloadContent(); if (!isUpdating) { VisualObjects.Remove(vo); } else { QueuedRemovals.Add(vo); } }
public T ChangeActor <T>(string name) where T : Actor, new() { VisualObject newObject = null; VisualObject oldObject = null; // loop thru the scene objects foreach (VisualObject o in VisualObjects) { if (o is Actor && o.Name == name) { Actor original = o as Actor; // Create our new Player Object T actor = new T { Game = Game, Name = original.Name, Direction = original.Direction, Position = original.Position, Scale = original.Scale, DrawOrder = original.DrawOrder, PlayerIndex = original.PlayerIndex, Enabled = original.Enabled, AssetName = original.AssetName, Role = original.Role, Visible = original.Visible, GameScreen = this }; // Init our animation clip player actor.ClipPlayer = new AnimationPlayer2D(Game) { AssetName = original.ClipPlayer.AssetName, Enabled = original.ClipPlayer.Enabled, Sequences = original.ClipPlayer.Sequences, Texture = original.ClipPlayer.Texture, GameScreen = this }; // init the new player object actor.Initialize(); // play the first sequence out the gate actor.Play(actor.ClipPlayer.Sequences[0].Name, true); // New Objects newObject = actor; // Remove it from scene manager oldObject = original; } } // Remove the old VisualObjects.Remove(oldObject); // Insert the new VisualObjects.Add(newObject); return(newObject as T); }