Managing the Ribbons
RibbonsManager is mainly a router, sending move method calls and update() and display() calls to the multiple Ribbon objects under its charge. Initially, it creates the Ribbon objects, so it acts as a central storage for their GIFs and move factors.
The initialization phase is carried out in the constructor:
// globals
private String ribImages[] = {"mountains", "houses", "trees"};
private double moveFactors[] = {0.1, 0.5, 1.0};
// applied to moveSize
// a move factor of 0 would make a ribbon stationary
private Ribbon[] ribbons;
private int numRibbons;
private int moveSize;
// standard distance for a ribbon to 'move' each tick
public RibbonsManager(int w, int h, int brickMvSz, ImagesLoader imsLd)
{ moveSize = brickMvSz;
// the basic move size is the same as the bricks map
numRibbons = ribImages.length;
ribbons = new Ribbon[numRibbons];
for (int i = 0; i < numRibbons; i++)
ribbons[i] = new Ribbon(w, h, imsLd.getImage( ribImages[i] ),
(int) (moveFactors[i]*moveSize));
} // end of RibbonsManager()The choice of GIFs is hardwired into ribImages[], and the constructor loops through the array creating a Ribbon object for each one.
The basic move size is the same as that used by the bricks layer but multiplied by a fixed moveFactors[] value to get a size suitable for each Ribbon.
Tip
A move size is the amount that a background layer moves in each animation period.
A move factor will usually be less than one, to reduce the move size for a Ribbon in comparison to the bricks ...