From 5af6f4d04ee3278ee68a289beca424c5aac61cdf Mon Sep 17 00:00:00 2001 From: Steffen Wilke Date: Wed, 18 Mar 2020 00:12:18 +0100 Subject: [PATCH] Allow custom creatures to override default controllers --- src/de/gurkenlabs/litiengine/entities/Creature.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/de/gurkenlabs/litiengine/entities/Creature.java b/src/de/gurkenlabs/litiengine/entities/Creature.java index 5a4f73def..06876e48f 100644 --- a/src/de/gurkenlabs/litiengine/entities/Creature.java +++ b/src/de/gurkenlabs/litiengine/entities/Creature.java @@ -11,6 +11,7 @@ import de.gurkenlabs.litiengine.environment.tilemap.TmxProperty; import de.gurkenlabs.litiengine.graphics.animation.CreatureAnimationController; import de.gurkenlabs.litiengine.graphics.animation.EntityAnimationController; +import de.gurkenlabs.litiengine.graphics.animation.IEntityAnimationController; import de.gurkenlabs.litiengine.physics.IMovementController; import de.gurkenlabs.litiengine.physics.MovementController; @@ -62,7 +63,7 @@ public Creature(String spritesheetName) { this.acceleration = movementInfo.acceleration(); this.deceleration = movementInfo.deceleration(); this.setTurnOnMove(movementInfo.turnOnMove()); - this.addController(new MovementController<>(this)); + this.addController(this.createMovementController()); } if (spritesheetName != null) { @@ -213,10 +214,18 @@ public String toString() { } protected void updateAnimationController() { - CreatureAnimationController controller = new CreatureAnimationController<>(this, true); + IEntityAnimationController controller = this.createAnimationController(); this.getControllers().addController(controller); if (Game.world().environment() != null && Game.world().environment().isLoaded()) { Game.loop().attach(controller); } } + + protected IEntityAnimationController createAnimationController() { + return new CreatureAnimationController<>(this, true); + } + + protected IMovementController createMovementController() { + return new MovementController<>(this); + } } \ No newline at end of file