CK_Object
|
+----CK_Image
|
+----CK_AnimatedImage
A CK_AnimatedImage contains an array of static images that represent an animation. The CK_AnimatedImage is a CK_Image, therefore it can be manipulated just like a static image. If the transparent color is set, it applies to all frames in the animation. If palettes are added to the palette set, they also apply to all frames of the animation.
A CK_AnimatedImage can be serialized to a file. The .can extention is for files containing a single serialized animated image. CK_AnimatedImage objects can also be stored as single entries in image tables (CK_ImageTable).
An animated image can contain a default frame rate, which is the number of frames per second at which the animation should run. The frame rate is stored with the object when serialized. This allows the frame rate to be set outside the application, and changed without requiring a change in the application code.
Animated images can be created in one of two ways. One way is to create the animation from a static image (CK_StaticImage) containing all the frames of the animation arranged in a grid. The other way is to create a CK_ImageFrame (from a CK_StaticImage) for each individual frame, and append each frame to the animation.
See CK_Image for more information.
Creates a CK_AnimatedImage from a serialized CK_AnimatedImage. The file pointer should be positioned at the beginning of the serialized animated image. On return, the file pointer will be positioned at the beginning of the next serialized object (if any) in the file.
- Return Value
- Returns a pointer to the created object, or 0 if no object could be created because the file pointer did not point to a serialized animated image.
Parameters
- fp
- File pointer pointing to the beginning of a serialized image. The file pointer should be from a file opened in binary mode:
FILE *fp = fopen("test.can","rb");
- com
- The name of a compression object to be used for decompressing the image data. If null, no decompression will occur. The compression object must be the same as that used when serializing the image.
Creates an empty CK_AnimatedImage. Frames can be added to the animation by calling appendFrame().
- Return Value
- Returns a pointer to the CK_AnimatedImage object created.
Creates a CK_AnimatedImage object from a .can file.
- Return Value
- Returns a pointer to the CK_AnimatedImage object created. If the file was missing, could not be opened, or did not contain the correct image file format, a null pointer is returned.
Parameters
- fileName
- The name of a .can file.
- com
- The name of a compression object to be used with .can files for decompressing the image data. If null, no decompression will occur. The compression object must be the same as that used when serializing the image.
Creates a CK_AnimatedImage from a static image (CK_StaticImage) that contains each frame of the animation arranged in grid. The figure below shows one possible layout of frames in the static image for an animation with 10 frames.
- Return Value
- Returns a pointer to the CK_AnimatedImage object created.
Parameters
- image
- The static image containing a grid of frames.
- nColumns
- The number of columns in the grid.
- frameWidth
- The width in pixels of each frame.
- frameHeight
- The height in pixels of each frame.
- numFrames
- The total number of frames in the animation. This does not need to be evenly divisible by the number of columns, as demonstrated in the example above.
Appends a frame to the end of the animation. The animated image has ownership of the image frame. When the animated image is deleted, each owned image frame will be deleted.
Parameters
- frame
- A CK_ImageFrame object representing one frame in the animation.
Removes a single frame from the animation. When the frame is removed, the CK_AnimatedImage no longer owns the frame.
- Return Value
- Returns a pointer to the extracted image frame.
Parameters
- frameIndex
- The index of the frame to be removed. The first frame in the animation is at index 0.
Returns the default frame rate (frames per second) of the animation. The default frame rate is stored with the animated image when the object is serialized.
Returns a const pointer to a single frame in the animation.
- Return Value
- A const pointer to the image frame is returned because the CK_AnimatedImage still owns the frame, and it should not be deleted or modified.
Parameters
- frameIndex
- The index of the frame to get. The first frame in the animation is at index 0.
Returns the number of frames in the animation.
Inserts a single frame into the animation.
Parameters
- frameIndex
- The index of the frame once it is inserted. Existing frames at frameIndex and above are shifted one index higher to make room for the inserted frame. Inserting a frame at index 0 will make it the first frame in the animation.
- frame
- The frame to be inserted.
Sets the default frame rate (frames per second) of the animation.
CK_AnimatedImage object are not drawable, so what is the point to setting a frame rate? CK_AnimatedImages are serializable, and the frame rate is stored with the object when serialized. A CK_AnimatedBitmap, which is drawable, can be created from a CK_AnimatedImage. The (drawable) animated bitmap will initialize its frame rate to that of the (non-drawable) animated image. The purpose is to allow the frame rate to be controlled outside of the application code.
Parameters
- frameRate
- The frame rate, in frames per second, of the animation.