Skip to content

[Sub-Issue] Add fluent tween builders with typed .start() and optional class-based API #59

@stringdotjar

Description

@stringdotjar

Currently, the way to create a tween is to manually create a FlixelTweenSettings object. This can cause annoyance with how much is required just to build one tween. To simplify this, we need to create static builder classes that automatically constructs tweens for all types.

Requirements:

Fluent builder API

  • Entry points return a builder; all configuration methods (e.g. addGoal, setEase, setType, setDuration) return the builder for chaining.
  • The chain ends with .start(), which creates the tween, adds it to the global manager, starts it, and returns it.

Typed return

Support a class reference (e.g. FlixelTween.tween(FlixelPropertyTween.class)) so that .start() returns the concrete type (e.g. FlixelPropertyTween), enabling something like:

// Reflection tween example.
FlixelPropertyTween tween = FlixelTween.tween(FlixelVarTween.class)
  .setObject(...)
  .addGoal(...)
  .setDuration(1f)
  .setCallback(values -> {...})
  .start();

// Property tween example.
FlixelPropertyTween tween = FlixelTween.tween(FlixelPropertyTween.class)
  .addGoal(...)
  .setDuration(1f)
  .start();

// Numerical tween example.
FlixelPropertyTween tween = FlixelTween.tween(FlixelNumTween.class)
  .from(1f)
  .to(2f)
  .setCallback(num -> {...})
  .setDuration(1f)
  .start(); // Make sure that the start method throws an exception if from, to or the update callback isn't set!

Metadata

Metadata

Assignees

Labels

coreCore logic module of the frameworkenhancementNew feature or requesthigh priorityMust be completed as soon as possiblerefactorParts of the code need to be moved, enhanced, changed, or removedtweeningCustom tweening system for adding animations on objects

Projects

Status

🗒️ Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions