/// <summary> /// Creates a new actor with a static sprite using the provided texture. /// </summary> public Actor(Game game, ActorBehavior[] newBehaviors, ContentManager content, string textureName) { this.game = game; behaviors = new List<ActorBehavior>(newBehaviors); sprite = Sprite.CreateStatic(content, textureName); }
/// <summary> /// Creates a new Actor. All ActorBehaviors must be provided here at once. /// </summary> public Actor(Game game, ActorBehavior[] newBehaviors) { this.game = game; behaviors = new List<ActorBehavior>(newBehaviors); }
/// <summary> /// Produces an exact clone of this actor. /// </summary> public Actor Clone() { // First we must clone all the behaviors. ActorBehavior[] behaviorClones = new ActorBehavior[behaviors.Count]; for (int i = 0; i < behaviors.Count; ++i) { ActorBehavior behavior = behaviors[i]; behaviorClones[i] = (ActorBehavior)behavior.Clone(); } Actor clone = new Actor(game, behaviorClones); clone.Sprite = sprite; clone.PhysicsBody = Physics.Dynamics.BodyFactory.Instance.CreateBody(physicsBody); clone.physicsGeom = Physics.Collisions.GeomFactory.Instance.CreateGeom(clone.PhysicsBody, physicsGeom); // We need to add the cloned physics body and geometry to the simulator. Physics.PhysicsSimulator physicsSimulator = (Physics.PhysicsSimulator)game.Services.GetService(typeof(Physics.PhysicsSimulator)); physicsSimulator.Add(clone.PhysicsBody); physicsSimulator.Add(clone.PhysicsGeom); // We need to loop through all the behaviors and assign the cloned actor as their parent. foreach (ActorBehavior behavior in clone.Behaviors) { behavior.ParentActor = clone; behavior.Initialize(); } return clone; }