Skip to content

Tweening

The TweenEngine (Game.tweens()) provides a high-performance property interpolation framework. It allows you to animate entity positions, camera zoom, opacity, sound volume, collision box dimensions, and UI components using mathematical easing equations.


Interactive Easing Curve Playground

Select an easing equation below to preview the interpolation curve and watch the live animation in real time:

Generated Java Code:
Game.tweens().begin(entity, TweenType.LOCATION_X, 1000)
    .target(400)
    .ease(TweenFunction.QUAD_OUT)
    .begin();
Curve Graph & Position Preview

The Tweening Engine — Game.tweens()

The tweening engine is a singleton manager accessed via Game.tweens(). It updates all active Tween instances during each engine update tick.

A Tween smoothly transitions numerical attributes from a starting value to an end value over a given duration:

TweenExample.java
ImageComponent ic = new ImageComponent(0, 0, 100, 100);

// Smoothly move ImageComponent to (100, 200) over 4 seconds using quadratic easing
Game.tweens().begin(ic, TweenType.LOCATION_XY, 4000)
    .target(100, 200)
    .ease(TweenFunction.QUAD_INOUT)
    .begin();

TweenType Reference

The TweenType enum defines all interpolatable entity and component properties:

TweenType Target Component Interpolated Property
LOCATION_X IEntity / GuiComponent X-coordinate map/screen position
LOCATION_Y IEntity / GuiComponent Y-coordinate map/screen position
LOCATION_XY IEntity / GuiComponent Simultaneous X and Y position coordinates
SIZE_WIDTH IEntity / GuiComponent Object bounding box width
SIZE_HEIGHT IEntity / GuiComponent Object bounding box height
SIZE_BOTH IEntity / GuiComponent Simultaneous width and height dimensions
ANGLE IEntity Rotation angle in degrees
COLLISION_WIDTH ICollisionEntity Physics collision box width
COLLISION_HEIGHT ICollisionEntity Physics collision box height
COLLISION_BOTH ICollisionEntity Physics collision box dimensions
HITPOINTS ICombatEntity Entity health pool (for smooth damage healthbars)
VELOCITY IMobileEntity Entity movement velocity
VOLUME Sound / SoundSource Audio volume multiplier (0.0 to 1.0)
OPACITY IEntity / GuiComponent Visual alpha transparency
FONTSIZE GuiComponent Text font rendering point size

TweenFunction Reference

LITIENGINE includes Robert Penner's complete collection of mathematical easing functions:

  • Linear: LINEAR (constant velocity without acceleration).
  • Quadratic (t²): QUAD_IN, QUAD_OUT, QUAD_INOUT (smooth, subtle curve).
  • Cubic (t³): CUBIC_IN, CUBIC_OUT, CUBIC_INOUT (pronounced acceleration/deceleration).
  • Circular: CIRCLE_IN, CIRCLE_OUT, CIRCLE_INOUT (mimics circular arc momentum).
  • Sinusoidal: SINE_IN, SINE_OUT, SINE_INOUT (gentle wave ease).
  • Exponential: EXPO_IN, EXPO_OUT, EXPO_INOUT (fast ramp-up/down).
  • Back (Overshoot): BACK_IN, BACK_OUT, BACK_INOUT (pulls back or overshoots target before settling).
  • Bounce: BOUNCE_IN, BOUNCE_OUT, BOUNCE_INOUT (simulates gravity rebounds).
  • Elastic: ELASTIC_IN, ELASTIC_OUT, ELASTIC_INOUT (spring-like oscillation).

Chaining & Lifecycle Listeners

TweenListeners.java
Game.tweens().begin(player, TweenType.LOCATION_XY, 1000)
    .target(500, 300)
    .ease(TweenFunction.BOUNCE_OUT)
    .onStart(tween -> System.out.println("Tween started!"))
    .onProgress((tween, value) -> System.out.println("Progress: " + value))
    .onComplete(tween -> {
      System.out.println("Tween completed!");
      // Chain another tween or play sound effect
      Resources.sounds().get("audio/land.ogg").play();
    })
    .begin();

See Also