Page:
Tweens
Pages
2D Drawing
2D Nodes
Code Edits
Code Services
Containers
Control Input
Engines
Exporting
File System Dock
Getting Started
Home
Input and Actions
Lisp Text
Live Pipelines
Painters
Playing a Game
Popups Menus and Dialogs
Popups and Dialogs
Project Manager
Projects
Render Targets
Resources
Saving Scenes
Scene Tree
Script Screen
Sessions
Signals
Status
The Debugger
The Editor
The REPL
Themes
Tweens
Undo and Redo
User Interface
Widgets
No results
2
Tweens
dxtr edited this page 2026-10-20 10:09:08 +02:00
Table of Contents
Tweens
A tween changes values over time, as Godot's Tween does: a spark that
grows and fades, a menu that slides in, a camera's zoom eased to where it
is wanted. create-tween makes one of a node, bound to it, and its
tweeners run in turn, or side by side with :parallel t. This spark,
added to a playing tree, grows and fades over a quarter of a second, then
frees itself:
(sc:define-node spark (s2d:node-2d)
((color :initarg :color :initform '(1 0.9 0.3 1) :type p2d:color :accessor spark-color
:property t)))
(defmethod (setf spark-color) :after (color (spark spark))
(declare (ignore color))
(s2d:queue-redraw spark))
(defmethod s2d:draw ((spark spark) canvas)
(p2d:fill-circle canvas 0 0 6 (spark-color spark)))
(defmethod sc:ready ((spark spark))
(let ((tween (sc:create-tween spark)))
(sc:tween-property tween spark :scale (gm:make-dvec2 :x 2 :y 2) 0.25
:transition :quad :ease :out)
(sc:tween-property tween spark '(:color :a) 0.0 0.25 :parallel t)
(sc:connect tween 'sc:finished spark 'sc:queue-free)))
Halfway, its scale is 1.75 and its colour's alpha 0.5.
- Making one:
(create-tween node)binds the tween to the node, which must be in a tree: it waits while the node is out of the tree or does not behave, as while its tree is edited, and goes once the node is freed.(create-tween tree)makes one bound to no node. The tree steps its tweens from its next frame, after each frame'sprocess, or with(setf (tween-process-mode tween) :physics)after each physics step, and lets one go once it finishes or is killed. Append the tweeners as the tween is made: nothing is appended once it has started. - Tweeners:
tween-propertychanges a property of an object, a node, a resource or another object with properties, to a value over some seconds;tween-intervalwaits;tween-callbackcalls a function;tween-methodcalls a function with a value changing over time, for what is no property; andtween-subtweenruns another tween of the tree as one step. Each runs after the one before, or beside it with:parallel t;(setf (tween-parallel tween) t)makes that the default, and:parallel nilruns one after. - Properties are named by their symbol, or by any symbol of their name,
as
:scale, or with a component, as(:color :a)or(:position :x). A property tweener changes from the value the property has as it begins, or from:from, or with:from-current tfrom the value it had as the tween was made;:relative tadds the value given to where it begins;:delaywaits first; and:interpolator, a function, maps the eased weight to the one used, as Godot's custom interpolators do. A value the property does not take, as an alpha beyond 1 where a transition overshoots, stops at the end it overshot. - Easing:
:transitionis one of Godot's twelve,:linear,:sine,:quad,:cubic,:quart,:quint,:expo,:circ,:elastic,:bounce,:backand:spring, and:easeone of:in,:out,:in-outand:out-in.tween-transitionandtween-easeare a tween's defaults,:linearand:in-outto begin with.ease-weightgives how far along an eased change is, andinterpolate-valuea value along one, for a game that eases values itself. - Running:
tween-loops, 1 by default, runs the steps that many times, or with no end for 0;tween-speed-scaleruns faster or slower;pause-tweenandplay-tweenpause and resume;stop-tweentakes it back to its start;kill-tweenends it for good; andstep-tweenadvances it by hand. A tween emitsstep-finished,loop-finishedandfinished, and each tweenerfinished, as signals. - Values: reals, integers rounded; cl-gmath's vectors and other
vectors, component by component; lists of reals as colours, as floats;
strings, by how much of them shows; and symbols, switching halfway.
Methods of
interpolateandadd-valuetween a game's own kinds of values. A component blends in its own float format, as a 2D node's position's x as a double-float. Stepping allocates nothing for single-float and integer properties, for vectors a property copies, as a 2D node's position, for a 2D node's position and scale components and its rotation, and for a property whose class gives the vector or cell of floats it is kept in withproperty-place, as a double-float kept in a cell (see Resources): the tween changes it there and callsproperty-place-changed, where the class does what setting the property does. Another double-float property is set with a new double-float each step, as Lisp passes one, and a list's values are made anew each step. - Errors: an error in what a tween does, a callback, a method, or
setting a property, stops its bound node, as an error in a callback
does, with
node-stopped; a tween bound to no node warns withtween-failed. Either way the tween is killed and the tree goes on. A tween with no end whose steps take no time is stopped, as Godot stops one.
Getting started
The core
Drawing
Scenes
User interface
Games and the editor
- Playing a Game
- Projects
- The Editor
- The File System Dock
- The Script Screen
- The REPL
- The Debugger
- Lisp Text
- Code Services
- Project Manager
- Undo and Redo
- Exporting
The project