diff --git a/src/de/gurkenlabs/litiengine/IUpdateable.java b/src/de/gurkenlabs/litiengine/IUpdateable.java index ce66885a7..d7d72d85e 100644 --- a/src/de/gurkenlabs/litiengine/IUpdateable.java +++ b/src/de/gurkenlabs/litiengine/IUpdateable.java @@ -1,15 +1,30 @@ package de.gurkenlabs.litiengine; +import de.gurkenlabs.litiengine.configuration.ClientConfiguration; + /** - * The Interface IUpdateable provides the functionality to update an instance - * from the game loop. The instance needs to register itself. + * The Interface IUpdateable provides the functionality to automatically update an instance that implements it + * from the game loop. The instance needs to be registered on the loop. + * + * @see ILoop#attach(IUpdateable) + * @see ILoop#detach(IUpdateable) */ public interface IUpdateable { /** - * This method is called by the game loop on all objects that need to update - * their attributes. It is called on every tick, means, it is called - * Game.GameLoop.TICKS_PER_SECOND times per second. + * This method is called by the game loop on all objects that are attached to the loop. + * It's called on every tick of the loop and the frequency can be configured using the ClientConfiguration. + * + * @see ClientConfiguration#setUpdaterate(int) */ public void update(); + + /** + * This flag controls whether this instance is currently active and thereby needs to be updated by the game loop. + * + * @return True if this instance should be updated; otherwise false. + */ + public default boolean isActive() { + return true; + } } diff --git a/src/de/gurkenlabs/litiengine/UpdateLoop.java b/src/de/gurkenlabs/litiengine/UpdateLoop.java index 5efe0faee..fa53a49ae 100644 --- a/src/de/gurkenlabs/litiengine/UpdateLoop.java +++ b/src/de/gurkenlabs/litiengine/UpdateLoop.java @@ -135,7 +135,7 @@ protected long getExpectedDelta() { protected void update() { for (IUpdateable updatable : this.getUpdatables()) { try { - if (updatable != null) { + if (updatable != null && updatable.isActive()) { updatable.update(); } } catch (final Exception e) { diff --git a/src/de/gurkenlabs/litiengine/configuration/ClientConfiguration.java b/src/de/gurkenlabs/litiengine/configuration/ClientConfiguration.java index 70752cd92..33f899b9c 100644 --- a/src/de/gurkenlabs/litiengine/configuration/ClientConfiguration.java +++ b/src/de/gurkenlabs/litiengine/configuration/ClientConfiguration.java @@ -92,6 +92,10 @@ public void setShowGameMetrics(final boolean showGameMetrics) { /** * Sets the updaterate. On a very good machine the max update rate is sth. * around 500 but such a high value will never be beneficial for the player. + * + *

+ * This defaults to a value of 60. + *

* * @param updaterate * the new updaterate