Skip to content

Refactor Tween to use event-based lifecycle instead of world container #1347

@obiot

Description

@obiot

Description

Currently, Tween extends Renderable and adds itself to game.world on start() to participate in the update loop. This is a workaround — tweens are not renderables, they are pure logic objects that interpolate values over time.

This approach creates an unnecessary dependency on the global game.world and makes tweens appear in the scene graph where they don't belong.

Proposed Solution

Tween should use the existing event system for lifecycle management instead of being a child of the world container:

  • Update: listen to TICK event instead of relying on the container's update() cycle
  • Timing: listen to GAME_AFTER_UPDATE for the latest game loop timestamp (already implemented)
  • Pause/Resume: listen to STATE_PAUSE / STATE_RESUME events
  • Cleanup: listen to GAME_RESET for auto-cleanup when the game resets

On start(), the tween subscribes to these events. On stop() or completion, it unsubscribes. No more game.world.addChild(this) / game.world.removeChildNow(this).

Benefits

  • Tween no longer extends Renderable (it's not a renderable)
  • Removes dependency on game.world global
  • Cleaner separation of concerns — tweens are logic, not scene graph nodes
  • Compatible with the Application-as-entry-point architecture
  • Simpler mental model for users

Breaking Changes

  • Tween will no longer be a Renderable — code that relies on tween being in the world container tree would need updating
  • Internal change, public tween API (to(), start(), stop(), onComplete(), etc.) remains the same

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions