Skip to content

Animation ​

Require path: require "ProjectMotionUI/Core/Animation"


Methods & Functions ​

PMUI.AnimationController:PlayEffect(name, duration, params, onComplete) ​

Starts a registered custom effect on the controlled element.

ParameterTypeDescription
namestringRegistered effect identifier.
durationnumber|nilEffect duration in seconds. Defaults to 0.5.
paramstable|nilParameters passed to the effect callbacks.
onCompletefunction|nilCallback invoked when the effect finishes.

PMUI.AnimationController:new(element) ​

Creates an animation controller for a UI element.

ParameterTypeDescription
elementPMUI.BaseElementElement controlled by this animation controller.

Returns: PMUI.AnimationController

PMUI.AnimationController:Tween(tag, props, duration, easing, onComplete) ​

Animates one or more element properties towards their target values. Starting a tween with an existing tag replaces the previous tween using that tag.

ParameterTypeDescription
tagstring|nilUnique tween identifier. Defaults to "default_tween".
propstableProperty names mapped to their target values.
durationnumber|nilAnimation duration in seconds. Defaults to 0.25.
easingfunction|nilEasing function used to interpolate values.
onCompletefunction|nilCallback invoked when the tween finishes.

PMUI.AnimationController:Spring(props, stiffness, damping) ​

Creates or updates spring animations for the specified element properties. Existing spring velocity is preserved when a property already has an active spring.

ParameterTypeDescription
propstableProperty names mapped to their target values.
stiffnessnumber|nilSpring stiffness. Defaults to 180.
dampingnumber|nilSpring damping. Defaults to 12.

PMUI.AnimationController:Impulse(vx, vy, stiffness, damping) ​

Applies an impulse to the element's animation offsets. Both offsets are animated back to zero using spring physics.

ParameterTypeDescription
vxnumber|nilInitial horizontal velocity.
vynumber|nilInitial vertical velocity.
stiffnessnumber|nilSpring stiffness. Defaults to 220.
dampingnumber|nilSpring damping. Defaults to 10.

PMUI.AnimationController:FallDown(bounciness, gravity, onComplete, initVx, initVy) ​

Simulates the element falling under gravity with horizontal movement and bouncing. The element remains within its parent or screen boundaries.

ParameterTypeDescription
bouncinessnumber|nilBounce strength, clamped between 0.1 and 0.85. Defaults to 0.5.
gravitynumber|nilDownward acceleration. Defaults to 2200.
onCompletefunction|nilCallback invoked when the element settles.
initVxnumber|nilInitial horizontal velocity.
initVynumber|nilInitial vertical velocity.

PMUI.AnimationController:RestoreFromFall(instant) ​

Stops the falling effect and restores the element to its original position.

ParameterTypeDescription
instantboolean|nilIf true, resets offsets immediately; otherwise uses spring animation.

PMUI.AnimationController:Shatter(cols, rows, force, onComplete) ​

Breaks the element into animated fragments that scatter and fade out. A temporary effect layer is created to render the fragments independently.

ParameterTypeDescription
colsnumber|nilNumber of fragment columns. Defaults to 4.
rowsnumber|nilNumber of fragment rows. Defaults to 3.
forcenumber|nilFragment scattering force. Defaults to 450.
onCompletefunction|nilCallback invoked after all fragments disappear.

PMUI.AnimationController:Shake(intensity, duration) ​

Applies a horizontal shake animation that gradually decreases in intensity.

ParameterTypeDescription
intensitynumber|nilMaximum horizontal displacement. Defaults to 6.
durationnumber|nilAnimation duration in seconds. Defaults to 0.35.

PMUI.AnimationController:Bounce(height, duration) ​

Moves the element vertically in a short bouncing motion.

ParameterTypeDescription
heightnumber|nilMaximum vertical displacement. Defaults to 8.
durationnumber|nilAnimation duration in seconds. Defaults to 0.3.

PMUI.AnimationController:FadeIn(duration, onComplete) ​

Fades the element in by animating its alpha from zero to one.

ParameterTypeDescription
durationnumber|nilFade duration in seconds. Defaults to 0.25.
onCompletefunction|nilCallback invoked when the fade finishes.

PMUI.AnimationController:FadeOut(duration, onComplete) ​

Fades the element out by animating its alpha to zero.

ParameterTypeDescription
durationnumber|nilFade duration in seconds. Defaults to 0.25.
onCompletefunction|nilCallback invoked when the fade finishes.

PMUI.AnimationController:SlideIn(direction, distance, duration, onComplete) ​

Slides the element into its original position from the specified direction.

ParameterTypeDescription
directionstringEntry direction: "left", "right", "top", or "bottom".
distancenumber|nilInitial displacement in pixels. Defaults to 40.
durationnumber|nilAnimation duration in seconds. Defaults to 0.3.
onCompletefunction|nilCallback invoked when the animation finishes.

PMUI.AnimationController:Update(dt) ​

Updates all active tweens, springs, and effects. Applies the resulting position changes after all animation calculations are complete.

ParameterTypeDescription
dtnumberTime elapsed since the previous update, in seconds.