O'Reilly logo

Killer Game Programming in Java by Andrew Davison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Displaying Image Sequences

ImagesPlayer is aimed at displaying the sequence of images making up an n, s, or g set of images.

The ImagesPlayer constructor takes the image's name, an animPeriod value, a seqDuration value, a Boolean indicating if the sequence should repeat, and a reference to the ImagesLoader:

    ImagesPlayer player = new ImagesPlayer(imagesName, animPeriod, seqDuration,
                                                   isRepeating, imsLoader);

seqDuration is the total time required to show the entire sequence. Internally, this is used to calculate showPeriod, the amount of time each image will be the current one before the next image takes its place. animPeriod states how often ImagesPlayer's updateTick() method will be called (the animation period). updateTick() will be called periodically by the update() method in the top-level animation framework.

The current time is calculated when updateTick() is called and used to calculate imPosition, which specifies which image should be returned when getCurrentImage() is called. This process is illustrated in Figure 6-5.

This approach relies on the animation loop calling updateTick() regularly at a fixed time interval, which is true for ImagesTests. Another implicit assumption is that the showPeriod time duration will be larger than animPeriod. For example, showPeriod might be in tenths of seconds even though animPeriod may be in milliseconds. If showPeriod is less than animPeriod, then rendering progresses too slowly to display all

Figure 6-5. ImagesPlayer in use

the images within ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required