The ANIMATION
command allows you to define an animation starting from a given
ATLAS
. The animation can be characterized by a type and parameters, which
describe its operation. Once defined, the animation can then be used at any time.
In order for this to work, you need to indicate a variable prefix that will be
associated with the object that will have this animation. This can be indicated with
the USING
keyword.
If the prefix
is a variable of type SPRITE
, CSPRITE
or MSPRITE
,
this movement will be bounded to that object. Otherwise, the following logic
will be applied.
This statement will generate a series of variables:
prefixFrame
, which will contain the next frame to be displayed for the animation;
prefixFrameDirection
, which will be 1 if the animation proceeds from the smallest frame to the largest frame and -1 vice versa;
prefixX
and prefixY
, which will contain the position where the animation will be displayed;
prefixOX
and prefixOY
will contain the previous coordinates;
prefixNext
, to signal / receive a synchonization event (see below);
prefixAnimation
that mantains the thread handle for this animation.
It is possible to indicate that a certain number of frames at the beginning of the
ATLAS
should be used as "ease in". This is done with the keyword EASEIN
,
followed by the number of frames and any delay to be applied between each frame.
It is also possible to indicate a certain number of frames from the end as belonging
to an "end of sequence" (also called "ease out"). With the keyword EASEOUT
it will
be possible to indicate the number of frames, and the delay between each of them.
If the animation needs to preserve the background, you need to add the PRESERVE BACKGROUND
keywords. This option will create an additional variable called prefixBackground
with
the image that is in the background of the animation before the animation is drawn.
On each redraw, the background will be restored before drawing the next frame.
If you need to synchronize with vertical blank, i.e. avoid flickering while drawing the
frame, you need to add the WAIT VBL
option.
Finally, you can indicate the name of an animation that will be executed at the end
of the current one, where the animation ends naturally or the signal to move to the
next one is sent. The animation is indicated with the keyword NEXT
and must already
be defined. If you need to use the ease in sequence, you need to use the
NEXT WITH EASEIN syntax.
The var prefixNext
deserves a special note. This variable acts as a bidirectional
data bus. By writing to this variable, you can send signals to the animation thread.
On the other hand, this variable is also written, and therefore you can get
information about the progress of the animation. In particular, bit 0, if active,
indicates that the "ease in" part of the animation has been executed; bit 1,
if active, indicates that the loop has been completed; bit 2, if active, indicates
that the "ease out" part of the animation has been executed; bit 3, if set externally
as active, indicates the request to exit an animation loop.
[DEFINE] ANIMATION type name WITH atlas [od] [in] [out] USING prefix [nx] [vbl] [bg] type: SIMPLE | LOOP | BOUNCE od: DELAY delay in: EASEIN upframe [DELAY delay] out: EASEOUT ofrom [DELAY delay] nx: NEXT [WITH EASIN] anim vbl: WAIT VBL bg: PRESERVE BACKGROUND
flyingAirplane := LOAD ATLAS("airplane.png") FRAME SIZE (16, 16) ANIMATION BOUNCE anim WITH flyingAirplane USING airplane
Join BASIC 10Liner Contest with ugBASIC!
An interesting competition is held at the beginning of each year: the
BASIC 10Liner Contest.
It is possible to use ugBASIC to participate in the next
"BASIC10Liner" competition, in the following categories:
ANIMATION ↔ Ani
If you have found a problem with this keyword, if you think there is a bug or, more
simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!
open an issue
BACK TO KEYWORDS