Files
orx/orx-delegate-magic
Edwin Jakobs b7ba6f6daa Feature variants (#376)
Migrate from buildSrc to build-logic. Setup feature variants.
2025-09-17 10:03:02 +02:00
..
2025-09-17 10:03:02 +02:00
2025-08-27 19:48:23 +00:00

orx-delegate magic

Collection of magical property delegators. For tracking variable change or interpolate towards the value of a variable.

Delegated properties

Kotlin documentation

Property smoothing

val state = object {
    var radius = 10.0
}

val smoothRadius by smoothing(state::radius)

Property dynamics

val state = object {
    var radius = 10.0
}

val dynamicRadius by springForcing(state::radius)

Property tracking

val state = object {
    var radius = 10.0
}

val radiusHistory by tracking(state::radius)

Demos

DemoDifferencing01

DemoDifferencing01Kt

source code

DemoFollowing01

Demonstrates using delegate-magic tools with [Double] and [Vector2].

The white circle's position uses [following]. The red circle's position uses [smoothing].

following uses physics (velocity and acceleration). smoothing eases values towards the target.

Variables using delegates (by) interpolate toward target values, shown as gray lines.

The behavior of the delegate-magic functions can be configured via arguments that affect their output.

The arguments come in pairs of similar name: The first one, often of type [Double], is constant, The second one contains Property in its name and can be modified after its creation and even be linked to a UI to modify the behavior of the delegate function in real time. The Property argument overrides the other.

DemoFollowing01Kt

source code

DemoSmoothing01

DemoSmoothing01Kt

source code

DemoSpring01

DemoSpring01Kt

source code