[Tutorial] Animation and Transforms by Example
Posted: Sun Aug 12, 2012 9:33 am
ATL is very intuitive and can add great polish to your game, but it can seem a little intimidating if you've never used it before. Hopefully people will find these examples useful. The wiki has a great section on Animation and Transformation Language.
Opacity
Custom fades are your friend--you can make a game look much more polished by adding custom fades to sprites instead of having them pop up and vanish. Here's a simple fade effect that occurs during one second. Alpha 0.0 is invisible and alpha 1.0 is opaque. "Linear" means seconds. We add "on show" and "on hide" to have effects for both.
Basic Animations
Realistic Rain
Search for rain animation tutorials to find an easy way to make images. I used this tutorial for Gimp. I got a nice result using three frames. Define your image by indicating the images and the amount of time between each:
If you want rain during an exterior, layer your images with rain at the end. (Images are layered on top of each other, so the first image shown will be at the "back" of the screen.)
If you want rain on outside of an interior scene, you would layer the rain before the interior image (which needs to have transparent windows or some other way to see the rain on the other side, of course).
You can also build a layered image using LiveComposite (it ain't just for sprites).
Flicker
You can take advantage of the Null command in animation loop to make an image flicker. It can create a neat effect on terminal-like objects and screens.
Basic Horizontal and Vertical Movement
This makes a little airplane go from the left to the right side of the screen over 45 seconds. Since I only used this effect once I included the position commands in the image definition, so you just type to get the effect.
You could drop a ball from the top of the screen to the bottom by adjusting the y-position instead.
Choice and Parallel - Adding Simultaneous and Random Elements
Randomized Lightning
This takes advantage of the choice command to use random images at random positions. Make three (or however many) lightning images, and define the image to show a random lighting picture using choice:
You can weight the likelihood of choices by adding an integer (the default is 1.0):
Now we will create a transform that causes the lightning to 1) appear at random places at the top of the screen and 2) flash. To do this we will use parallel statements, which allow us to executes multiple ATL blocks at the same time. The first parallel block sets the image position at one of three x-positions at the top of the screen. The second parallel block causes the image to appear and disappear within 0.5 seconds, simulating a flash.
Combine Horizontal and Vertical Motion
In Locked-In there is a scene where a waiter walks by a with a dinner tray. I made the tray move from right to left, AND slightly up and down to simulate walking, by splitting the y movement and the x movement into two parallel blocks.
Rotate
Analog Clock
For this you will need a separate clock face, minute hand, and hour hand. The hour hand rotates in 60 seconds and the minute hand rotates in 5 seconds. If you get a bad jitter effect on slow rotations you can add subpixel True to smooth things out.
If you want the hands to rotate counter-clockwise, you can do it by giving a negative rotation:
Swinging Back and Forth
This is how I made the padlock on the Locked-In logo swing back and forth before coming to a standstill. I use a block statement to separate the latter part of the transform.
If you wanted it to swing back and forth indefinitely, you could do it using a repeating block:
As you can see, zoom is conspicuously absent. If anyone wants to add their own examples/improvements, please do.
Opacity
Custom fades are your friend--you can make a game look much more polished by adding custom fades to sprites instead of having them pop up and vanish. Here's a simple fade effect that occurs during one second. Alpha 0.0 is invisible and alpha 1.0 is opaque. "Linear" means seconds. We add "on show" and "on hide" to have effects for both.
Code: Select all
transform basicfade:
on show:
alpha 0.0
linear 1.0 alpha 1.0
on hide:
linear 1.0 alpha 0.0
Code: Select all
show eileen at basicfade, center
e "Here I am!"
e "Buh-bye now!"
hide elieen
Realistic Rain
Search for rain animation tutorials to find an easy way to make images. I used this tutorial for Gimp. I got a nice result using three frames. Define your image by indicating the images and the amount of time between each:
Code: Select all
image rain:
"rain.png"
0.1
"rain2.png"
0.1
"rain3.png"
0.1
repeat
Code: Select all
scene darksky
show house
show rain
Code: Select all
scene darksky
show rain
show bedroom
You can also build a layered image using LiveComposite (it ain't just for sprites).
Code: Select all
image bedroom:
LiveComposite((800,600), (0,0), "darksky", (0,0), "rain", (0,0), "bedroom.png")
Code: Select all
scene bedroom
You can take advantage of the Null command in animation loop to make an image flicker. It can create a neat effect on terminal-like objects and screens.
Code: Select all
image monitor:
"scanlines.png"
1.4
Null ()
0.05
"scanlines.png"
4.0
Null ()
0.05
repeat
This makes a little airplane go from the left to the right side of the screen over 45 seconds. Since I only used this effect once I included the position commands in the image definition, so you just type
Code: Select all
show airplane
Code: Select all
image airplane:
"airplane.png"
xalign -0.1 yalign 0.15
linear 45.0 xalign 1.1
Code: Select all
transform falling:
yalign 0.0 xalign 0.5
linear 1.0 yalign 1.0
Code: Select all
show ball at falling
Choice and Parallel - Adding Simultaneous and Random Elements
Randomized Lightning
This takes advantage of the choice command to use random images at random positions. Make three (or however many) lightning images, and define the image to show a random lighting picture using choice:
Code: Select all
image lightning:
choice:
"lightning.png"
choice:
"lightning2.png"
choice:
"lightning3.png"
Code: Select all
choice 3.0:
"lightning.png"
Code: Select all
transform flash:
parallel:
yalign 0.0
choice:
xalign 0.9
choice:
xalign 0.5
choice:
xalign 0.1
parallel:
alpha 0.0
linear 0.25 alpha 1.0
linear 0.25 alpha 0.0
Code: Select all
show lightning at flash
In Locked-In there is a scene where a waiter walks by a with a dinner tray. I made the tray move from right to left, AND slightly up and down to simulate walking, by splitting the y movement and the x movement into two parallel blocks.
Code: Select all
transform tray:
parallel:
xalign 2.5
linear 4.0 xalign -2.0
parallel:
yalign 1.5
block:
linear 1.0 yalign 1.0
linear 1.0 yalign 1.5
repeat
Analog Clock
For this you will need a separate clock face, minute hand, and hour hand. The hour hand rotates in 60 seconds and the minute hand rotates in 5 seconds. If you get a bad jitter effect on slow rotations you can add subpixel True to smooth things out.
Code: Select all
transform hoursforward:
subpixel True
rotate 0
linear 60.0 rotate 360
repeat
Code: Select all
transform minutesforward:
subpixel True
rotate 0
linear 5.0 rotate 360
repeat
Code: Select all
transform hoursbackward:
subpixel True
rotate 0
linear 60.0 rotate -360
repeat
This is how I made the padlock on the Locked-In logo swing back and forth before coming to a standstill. I use a block statement to separate the latter part of the transform.
Code: Select all
transform lock:
rotate 0
linear 0.0 rotate 30
block:
linear 0.75 rotate -30
linear 0.65 rotate 25
linear 0.60 rotate -25
linear 0.55 rotate 20
linear 0.50 rotate -20
linear 0.45 rotate 15
linear 0.35 rotate -15
linear 0.30 rotate 10
linear 0.25 rotate -10
linear 0.20 rotate 5
linear 0.15 rotate -5
linear 0.1 rotate 0
Code: Select all
transform lock:
rotate 0
linear 0.0 rotate 30
block:
linear 0.75 rotate -30
linear 0.75 rotate 30
repeat