Changing a Cel through Its CCB


A cel is animated by reprojecting the cel in each frame of the display and changing the cel's parameters from one frame to the next. The bitmapped background is typically refreshed between frames (as described in the last chapter) so that the cel's last projection is wiped clean before the new projection appears. A consistent change of cel characteristics from one frame to the next gives the cel the illusion of motion or animation.

To animate a cel, you change its CCB between frames. The Graphics folio's wait call, WaitVBL(), helps time the CCB changing calls to occur during the vertical blank interval between frames. If you are double-buffering the animation, during or after the vertical blank you can project cels into the bitmap that is not displayed-just be sure you finish projection before the next vertical blank.

Changing Cel Position

To change a cel's position within a bitmap or a screen, change the XPOS and YPOS values in the CCB from frame to frame. You can use fractional pixels for fine motion, and you can specify locations beyond the boundaries of the bitmap or screen on which you are projecting the cel. Cels are clipped when they go past bitmap or screen boundaries, or when they go past clipping boundaries set by SetClipHeight() and SetClipWidth().

Changing a Cel's Projection Quadrilateral

To change the shape or size of a cel (shrink it, enlarge it, or distort it), you can directly change the HDX, HDY, VDX, VDY, HDDX, and HDDY words of the CCB to set the cel's projection quadrilateral. This requires calculation to figure the appropriate slopes for the external and row boundaries of the cel. You can also use MapCel() to determine the projection quadrilateral.

MapCel() accepts two arguments: a pointer to a cel's CCB and a pointer to an array of four point structures. These four point structures set the four corners of the cel's projection quadrilateral. MapCel() works out the projection quadrilateral from the four points, and automatically sets the quadrilateral offsets in the CCB.

The four-point projection quadrilateral structure contains four pairs of point coordinates, the x coordinate followed by the y coordinate. Each point coordinate is a 32-bit value that is in 16.16 format. The four points within the structure are tied to the corners of the original cel source data, starting with the upper-left corner and proceeding clockwise:

The points do not need to retain their clockwise nature; they can be rearranged to flip the cel vertically or horizontally, to twist the cel into a bow-tie shape, or to change the cel into whatever distorted shape you want that can be defined with four corner points.

Skipping a Cel Within a Linked Group

When projecting a linked cel group over many frames, you may want to skip projecting one or more cels from the group. For example, an airplane object consisting of many linked cels could retract its landing gear. Once retracted, the landing gear cel within the group no longer needs to be projected.

To skip a cel within a group, simply set the SKIP flag within the FLAGS word of its CCB. The connections between cels within the group remain intact, but the cel engine does not project any cels whose SKIP flags are set, saving cel engine processing time.

Sequentially Animating a Cel

Although cels can be animated effectively by changing their position and projection quadrilateral, some animation is best done by flipping through a series of images-sequentially animating a cel. To sequentially animate a cel, you must create a series of source data files that contain the sequence of images you want to cycle within the cel. To keep things simple, these source data files should all use the same data type: either coded or uncoded, packed or unpacked, the same number of bits per pixel, and have the same dimensions. When multiple source data files are uniform in type and dimension, they can use the same preamble, which should be included within the CCB to save RAM.

Once multiple source data files are set up, a cel can be sequentially animated by changing the contents of the CCB's SOURCEPTR word from frame to frame. SOURCEPTR points to a different source data file for each frame, and so presents a sequence of images within the cel. You can go through images in any order you wish, cycling through source data files, working forward and then backward through them, jumping from place to place, or whatever works best. You can also load new source data files to replace old ones that are no longer used.

While a cel is sequentially animated from frame to frame, you can add to its animation by changing its position and its projection quadrilateral.