/// <summary> /// Destroys the specified actor and removes it from memory /// NOTE: An actor MUST be in the scene's actor collection to exist. Actors removed from the collection /// are dereferenced completely. /// </summary> /// <param name="_actor"></param> public void DestroyActor(EditorActor _actor) { if (_actor != null) { try { //Find the actor foreach (EditorActor _a in SCENE_ACTORS) { if (_a.GetUniqueId() == _actor.GetUniqueId()) { //Call the actor's dispose method if (_a.Destroy() == 0) { //Remove the actor from the list SCENE_ACTORS.Remove(_a); //Dereference and call GC GC.Collect(); return; } } } Editor.EngineMessage("ERROR: Failed to destroy scene actor because the actor does not exist.", Editor.eEngineMessageType.EXCEPTION); return; } catch (NullReferenceException _n) { Editor.EngineMessage(_n.Message, Editor.eEngineMessageType.EXCEPTION); } } }
/// <summary> /// Actor Collection Methods /// </summary> public void AddActorToScene(ref EditorActor _newActor) { if (_newActor != null) { //Generate new unique id for this actor _newActor.GenerateUniqueId(); try { _newActor.position = _newActor.position - new Vector2f(_newActor.actorSprite.Texture.Size.X / 2, _newActor.actorSprite.Texture.Size.Y / 2); SCENE_ACTORS.Add(_newActor); _newActor.Create(); } catch (NullReferenceException _n) { Editor.EngineMessage(_n.Message, Editor.eEngineMessageType.EXCEPTION); } } else { Editor.EngineMessage("ERROR: FAILED TO ADD ACTOR TO SCENE BECAUSE THE OBJECT YOU ARE TRYING TO ADD IS NULL"); } }