Java Reference
In-Depth Information
Figure 7-6. Entire sequence
As you see, there is only a minor variation between each frame, but there are enough frames to
make it look like the asteroid is spinning around. Also note how similar the last asteroid is to the first.
This creates animation that is not jerky when going from the last image to the first. But they are not
identical either, as that would cause a quick but annoying pause in the animation.
To animate a number of images they must first be loaded. It is important to load an image in an
application only once, otherwise it is costly in memory and speed. The example code shows a simple
way to ensure that images are loaded just one time. It also shows how the images can be loaded at the
start of the app, which will remove any pauses later in the running of the app.
The second step is to cycle the images in the scene to create the frames of an animation. Listing 7-1
shows how these two steps—loading and cycling images—are achieved with the provided classes.
Further listings will show the details of each class used in this example.
Listing 7-1. Main.fx
var sequenceView:ImageSequenceView;
var anim = Timeline{
repeatCount: Timeline.INDEFINITE
keyFrames: KeyFrame{
time: 1.0/30.0*1s
action: function(){
function run():Void{
var seq1 = MediaLoader.imageSequence("/org/lj/jfxe/chapter7/images/asteroidA_64_", 31,
var seq2 = MediaLoader.imageSequence("/org/lj/jfxe/chapter7/images/bomb-pur-64-", 61,
var seq3 = MediaLoader.imageSequence("/org/lj/jfxe/chapter7/images/Explosion01_", 35,
var asteroidButton = Button{
text: "Asteroid"
action: asteroid
Search WWH ::

Custom Search