![]() |
CRM64Pro GDK v0.13.0
A free cross-platform game development kit built on top of SDL 3.0
|
Sprite Manager and Sprite objects for handling animated sprite sheets [v25.12.0].
The Sprite module provides management for sprites and sprite animations. Sprites are collections of smaller images of uniform, rectangular size contained on an image sprite sheet that can be animated. Each sprite sheet has associated logic that represents different animation states, types and frames with time durations.
Currently, there is one version of the Sprite Object (v1.0) with the following capabilities:
| Animation states | 9 high-states with up to 255 low-states each (total: 2295 animations) |
|---|---|
| Animation types | Loop, ping-pong and one-shot |
| Hotspots | Configurable per animation |
| Frames per animation | Up to 123 frames |
| Frame duration | 0 to 65536 milliseconds (up to 65 seconds) |
| Loop | Animation cycles continuously from first to last frame, then restarts |
|---|---|
| Ping-pong | Animation plays forward then backward, repeating indefinitely |
| One-shot | Animation plays once and stops on the last frame |
| Sprite management | Create, load, save and manage sprite objects |
|---|---|
| Animation control | Configure states, types, frames and timing |
| Image integration | Get Image ID to access the underlying Image object (export, alpha modulation, etc.) |
| Format | CDC v1.x specification |
|---|---|
| load() | Load sprite from CDC archive |
| save() | Save sprite to CDC archive |
This is an advanced "cloning" manager: when loading a sprite from a CDC file that is already loaded or created (using the name as the key), it will create a new child sprite. Child sprites share base data with the parent while allowing independent animation state and playback.
Classes | |
| class | CRM64Pro::Sprite |
| Sprite Object class. More... | |
| class | CRM64Pro::SpriteMgr |
| Sprite Manager class. More... | |
Macros | |
| #define | SPR_TYPE_LOOP 1 |
| #define | SPR_TYPE_PINGPONG 2 |
| #define | SPR_TYPE_ONESHOT 4 |
| #define | SPR_STATE_NORMAL 0x8000 |
| #define | SPR_STATE_UP 0x4000 |
| #define | SPR_STATE_DOWN 0x2000 |
| #define | SPR_STATE_LEFT 0x1000 |
| #define | SPR_STATE_RIGHT 0x0800 |
| #define | SPR_STATE_UPLEFT 0x0400 |
| #define | SPR_STATE_UPRIGHT 0x0200 |
| #define | SPR_STATE_DOWNLEFT 0x0100 |
| #define | SPR_STATE_DOWNRIGHT 0xC000 |
| #define | SPR_GET_HIGHSTATE(x) |
| #define | SPR_GET_LOWSTATE(x) |
Functions | |
| Sint32 | CRM64Pro::Sprite::info (Sint32 iMode=0) |
| Request Sprite object information. | |
| Sint32 | CRM64Pro::Sprite::getName (string &sName) |
| Get the name. | |
| Uint32 | CRM64Pro::Sprite::getID () |
| Get the ID. | |
| Sint32 | CRM64Pro::Sprite::assignImage (Sint32 idImage, Sint32 iOwnership=0) |
| Assign an Image to this sprite. | |
| Sint32 | CRM64Pro::Sprite::getImage () |
| Get the assigned Image of this sprite. | |
| Sint32 | CRM64Pro::Sprite::setOffset (Sint32 iX, Sint32 iY) |
| Set the sprite offsets for creating the animations and frames. | |
| Sint32 | CRM64Pro::Sprite::getOffset (Sint32 *iX, Sint32 *iY) |
| Get the sprite offsets (frames and animations). | |
| Sint32 | CRM64Pro::Sprite::pause () |
| Pause the sprite animation. | |
| Sint32 | CRM64Pro::Sprite::resume () |
| Resume from a previous paused sprite animation. | |
| Sint32 | CRM64Pro::Sprite::status () |
| Get the sprite status. | |
| Sint32 | CRM64Pro::Sprite::setSpeed (float fSpeed) |
| Set the sprite speed. | |
| Sint32 | CRM64Pro::Sprite::getAnimNumber () |
| Get number of animations. | |
| Sint32 | CRM64Pro::Sprite::getAnimCurrent () |
| Get current animation number. | |
| Sint32 | CRM64Pro::Sprite::selectAnim (Sint32 iAnim) |
| Select an animation by state or by number. | |
| Sint32 | CRM64Pro::Sprite::setAnimType (Sint32 iAnim, Sint32 iType) |
| Set the animation type. | |
| Sint32 | CRM64Pro::Sprite::getAnimType (Sint32 iAnim, Sint32 *iType) |
| Get the animation type. | |
| Sint32 | CRM64Pro::Sprite::setAnimState (Sint32 iAnim, Sint32 iState) |
| Set the animation state. | |
| Sint32 | CRM64Pro::Sprite::getAnimState (Sint32 iAnim, Sint32 *iState) |
| Get the animation state. | |
| Sint32 | CRM64Pro::Sprite::orderAnimState (Sint32 iState=-1) |
| Ordering the low-state values. | |
| Sint32 | CRM64Pro::Sprite::setAnimHotSpot (Sint32 iAnim, Sint32 iHotX, Sint32 iHotY) |
| Set the animation hotspot. | |
| Sint32 | CRM64Pro::Sprite::getAnimHotSpot (Sint32 iAnim, Sint32 *iHotX, Sint32 *iHotY) |
| Get the animation hotspot. | |
| Sint32 | CRM64Pro::Sprite::setAnimRange (Sint32 iAnim, Sint32 iFrameStart, Sint32 iFrameEnd) |
| Set the animation frame range. | |
| Sint32 | CRM64Pro::Sprite::getAnimRange (Sint32 iAnim, Sint32 *iFrameStart, Sint32 *iFrameEnd) |
| Get the animation frame range. | |
| Sint32 | CRM64Pro::Sprite::getFrameNumber (Sint32 iAnim) |
| Get number of frames for the given animation. | |
| Sint32 | CRM64Pro::Sprite::getFrameCurrent () |
| Get current frame number for the given animation. | |
| Sint32 | CRM64Pro::Sprite::selectFrame (Sint32 iAnim, Sint32 iFrame) |
| Select a frame for the given animation. | |
| Sint32 | CRM64Pro::Sprite::setFrameTime (Sint32 iAnim, Sint32 iFrame, Uint16 iTime) |
| Set the frame time duration. | |
| Sint32 | CRM64Pro::Sprite::getFrameTime (Sint32 iAnim, Sint32 iFrame, Uint16 *iTime) |
| Get the frame time duration. | |
| Sint32 | CRM64Pro::Sprite::setPosition (float fX, float fY, Sint32 iInterpolation=0) |
| Set the sprite position. | |
| Sint32 | CRM64Pro::Sprite::getPosition (float *fX, float *fY) |
| Get the sprite position. | |
| Sint32 | CRM64Pro::Sprite::render (Sint32 idRes=0) |
| Render the sprite. | |
| Sint32 | CRM64Pro::Sprite::save (const string &sFileCDC) |
| Save the sprite to a CDC file. | |
| Sint32 | CRM64Pro::Sprite::save (Sint32 idCDC) |
| Save the sprite to a CDC file. | |
| Sint32 | CRM64Pro::SpriteMgr::info (Sint32 iMode=0) |
| Request Sprite Manager information. | |
| Sint32 | CRM64Pro::SpriteMgr::create (const string &sName, Uint32 iVersion=10) |
| Create a new sprite. | |
| Sint32 | CRM64Pro::SpriteMgr::close (Sint32 idSprite) |
| Close and destroy a sprite. | |
| Sint32 | CRM64Pro::SpriteMgr::getNum () const |
| Get number of loaded objects. | |
| Sint32 | CRM64Pro::SpriteMgr::setName (Sint32 idSprite, const string &sName) |
| Change the object name. | |
| Sprite * | CRM64Pro::SpriteMgr::get (Sint32 idSprite) |
| Get a pointer to the sprite using its handler. | |
| Sint32 | CRM64Pro::SpriteMgr::child (Sint32 idSprite) |
| Create a child sprite dependent on the provided one (the parent). | |
| Sint32 | CRM64Pro::SpriteMgr::load (const string &sFileCDC, const string &sName) |
| Load a sprite stored in a CDC file. | |
| Sint32 | CRM64Pro::SpriteMgr::load (const Sint32 idCDC, const string &sName) |
| Load a sprite stored in a CDC file. | |
| Sint32 | CRM64Pro::SpriteMgr::remove (const Sint32 idCDC, const string &sName) |
| Remove a sprite stored in a CDC file. | |
| #define SPR_TYPE_LOOP 1 |
Sprite animation type: loop.
| #define SPR_TYPE_PINGPONG 2 |
Sprite animation type: ping-pong.
| #define SPR_TYPE_ONESHOT 4 |
Sprite animation type: one-shot.
| #define SPR_STATE_NORMAL 0x8000 |
Sprite animation high-state: normal (10000000-00000000)
| #define SPR_STATE_UP 0x4000 |
Sprite animation high-state: up (01000000-00000000)
| #define SPR_STATE_DOWN 0x2000 |
Sprite animation high-state: down (00100000-00000000)
| #define SPR_STATE_LEFT 0x1000 |
Sprite animation high-state: left (00010000-00000000)
| #define SPR_STATE_RIGHT 0x0800 |
Sprite animation high-state: right (00001000-00000000)
| #define SPR_STATE_UPLEFT 0x0400 |
Sprite animation high-state: up-left (00000100-00000000)
| #define SPR_STATE_UPRIGHT 0x0200 |
Sprite animation high-state: up-right (00000010-00000000)
| #define SPR_STATE_DOWNLEFT 0x0100 |
Sprite animation high-state: down-left (00000001-00000000)
| #define SPR_STATE_DOWNRIGHT 0xC000 |
Sprite animation high-state: down-right (11000000-00000000)
| #define SPR_GET_HIGHSTATE | ( | x | ) |
Each state is a 16bit value; the high byte sets the high-state defined by the GDK. Use this macro for getting the sprite animation high-state. See SPR_STATE_xx above.
| #define SPR_GET_LOWSTATE | ( | x | ) |
Each state is a 16bit value; the low byte sets the low-state (up to 256) which can be user-defined. Use this macro for getting the sprite animation low-state.
| Sint32 CRM64Pro::Sprite::info | ( | Sint32 | iMode = 0 | ) |
Request Sprite object information.
Writes information to the default log.
| iMode | 0 for standard output and 1 for extended output including frame times. |
| Sint32 CRM64Pro::Sprite::getName | ( | string & | sName | ) |
Get the name.
| sName | a string containing the sprite name. |
| Uint32 CRM64Pro::Sprite::getID | ( | ) |
Get the ID.
| Sint32 CRM64Pro::Sprite::assignImage | ( | Sint32 | idImage, |
| Sint32 | iOwnership = 0 ) |
Assign an Image to this sprite.
Used for loading an Image when the sprite is created with SpriteMgr::create().
| idImage | Image id containing the sprite sheet. |
| iOwnership | 0 (default) creates a copy; any other value takes ownership (image cannot be owned by another item). |
| Sint32 CRM64Pro::Sprite::getImage | ( | ) |
Get the assigned Image of this sprite.
| Sint32 CRM64Pro::Sprite::setOffset | ( | Sint32 | iX, |
| Sint32 | iY ) |
Set the sprite offsets for creating the animations and frames.
Non-exact offset division is allowed; remainder parts are unused.
| iX | offset X for creating frames. Image width is divided by this value. A scanning process detects empty frames (colorkey or alpha) to set animation end. |
| iY | offset Y for creating animations and setting frame height. Image height is divided by this value. |
| Sint32 CRM64Pro::Sprite::getOffset | ( | Sint32 * | iX, |
| Sint32 * | iY ) |
Get the sprite offsets (frames and animations).
| iX | an integer pointer filled in with sprite offset X (width of each frame). If nullptr is passed, the method ignores the retrieving of this value. |
| iY | an integer pointer filled in with sprite offset Y (height of each frame). If nullptr is passed, the method ignores the retrieving of this value. |
| Sint32 CRM64Pro::Sprite::pause | ( | ) |
Pause the sprite animation.
| Sint32 CRM64Pro::Sprite::resume | ( | ) |
Resume from a previous paused sprite animation.
| Sint32 CRM64Pro::Sprite::status | ( | ) |
Get the sprite status.
| Sint32 CRM64Pro::Sprite::setSpeed | ( | float | fSpeed | ) |
Set the sprite speed.
| fSpeed | float number setting the relative speed (e.g. 0.5 = 50% slower). Default 1.0. |
| Sint32 CRM64Pro::Sprite::getAnimNumber | ( | ) |
Get number of animations.
| Sint32 CRM64Pro::Sprite::getAnimCurrent | ( | ) |
Get current animation number.
| Sint32 CRM64Pro::Sprite::selectAnim | ( | Sint32 | iAnim | ) |
Select an animation by state or by number.
| iAnim | the animation state (high-state + low-state) or the animation number from 0 to getAnimNumber(). |
| Sint32 CRM64Pro::Sprite::setAnimType | ( | Sint32 | iAnim, |
| Sint32 | iType ) |
Set the animation type.
| iAnim | the animation state (high-state + low-state) or the animation number from 0 to getAnimNumber(). |
| iType | Animation type. Check SPR_TYPE_LOOP, SPR_TYPE_PINGPONG and SPR_TYPE_ONESHOT definition for further information. |
| Sint32 CRM64Pro::Sprite::getAnimType | ( | Sint32 | iAnim, |
| Sint32 * | iType ) |
Get the animation type.
| iAnim | the animation state (high-state + low-state) or animation number from 0 to getAnimNumber(). Use -1 for current animation. |
| iType | pointer filled with animation type (SPR_TYPE_LOOP, SPR_TYPE_PINGPONG or SPR_TYPE_ONESHOT). |
| Sint32 CRM64Pro::Sprite::setAnimState | ( | Sint32 | iAnim, |
| Sint32 | iState ) |
Set the animation state.
| iAnim | the animation state (high-state + low-state) or animation number from 0 to getAnimNumber(). |
| iState | Animation state (high-state + low-state). Each high-state should have unique low-state values; otherwise only the first match is used. Use orderAnimState() to reorder low-state values. |
| Sint32 CRM64Pro::Sprite::getAnimState | ( | Sint32 | iAnim, |
| Sint32 * | iState ) |
Get the animation state.
| iAnim | the animation state (high-state + low-state) or animation number from 0 to getAnimNumber(). Use -1 for current animation. |
| iState | pointer filled with animation state (high-state + low-state). |
| Sint32 CRM64Pro::Sprite::orderAnimState | ( | Sint32 | iState = -1 | ) |
Ordering the low-state values.
| iState | Animation state (high-state + low-state) for ordering. Default -1 orders all states. Assigns values 0 to n as they appear (from animation 0 to number of animations). |
| Sint32 CRM64Pro::Sprite::setAnimHotSpot | ( | Sint32 | iAnim, |
| Sint32 | iHotX, | ||
| Sint32 | iHotY ) |
Set the animation hotspot.
| iAnim | the animation state (high-state + low-state) or the animation number from 0 to getAnimNumber(). |
| iHotX | the x hotspot position of the animation. You can set any value or ::PH_CENTER and ::PH_SIZE enum values. |
| iHotY | the y hotspot position of the animation. You can set any value or ::PH_CENTER and ::PH_SIZE enum values. |
| Sint32 CRM64Pro::Sprite::getAnimHotSpot | ( | Sint32 | iAnim, |
| Sint32 * | iHotX, | ||
| Sint32 * | iHotY ) |
Get the animation hotspot.
| iAnim | the animation state (high-state + low-state) or animation number from 0 to getAnimNumber(). Use -1 for current animation. |
| iHotX | pointer filled with X hotspot position. If nullptr, value is not retrieved. |
| iHotY | pointer filled with Y hotspot position. If nullptr, value is not retrieved. |
| Sint32 CRM64Pro::Sprite::setAnimRange | ( | Sint32 | iAnim, |
| Sint32 | iFrameStart, | ||
| Sint32 | iFrameEnd ) |
Set the animation frame range.
| iAnim | the animation state (high-state + low-state) or the animation number from 0 to getAnimNumber(). |
| iFrameStart | an integer with the start frame number [0, number of frames). If -1 is passed, the method ignores the setting of this value. |
| iFrameEnd | an integer with the end frame number [0, number of frames). If -1 is passed, the method ignores the setting of this value. |
| Sint32 CRM64Pro::Sprite::getAnimRange | ( | Sint32 | iAnim, |
| Sint32 * | iFrameStart, | ||
| Sint32 * | iFrameEnd ) |
Get the animation frame range.
| iAnim | the animation state (high-state + low-state) or animation number from 0 to getAnimNumber(). Use -1 for current animation. |
| iFrameStart | an integer pointer filled in with the start frame number [0, number of frames). If nullptr is passed, the method ignores the retrieving of this value. |
| iFrameEnd | an integer pointer filled in with the end frame number [0, number of frames). If nullptr is passed, the method ignores the retrieving of this value. |
| Sint32 CRM64Pro::Sprite::getFrameNumber | ( | Sint32 | iAnim | ) |
Get number of frames for the given animation.
| iAnim | the animation state (high-state + low-state) or animation number from 0 to getAnimNumber(). Use -1 for current animation. |
| Sint32 CRM64Pro::Sprite::getFrameCurrent | ( | ) |
Get current frame number for the given animation.
| Sint32 CRM64Pro::Sprite::selectFrame | ( | Sint32 | iAnim, |
| Sint32 | iFrame ) |
Select a frame for the given animation.
| iAnim | the animation state (high-state + low-state) or the animation number from 0 to getAnimNumber(). |
| iFrame | frame number from 0 to getFrameNumber() to be selected. |
| Sint32 CRM64Pro::Sprite::setFrameTime | ( | Sint32 | iAnim, |
| Sint32 | iFrame, | ||
| Uint16 | iTime ) |
Set the frame time duration.
| iAnim | the animation state (high-state + low-state) or the animation number from 0 to getAnimNumber(). |
| iFrame | frame number from 0 to getFrameNumber() to be selected. With -1, it applies iTime to all frames. |
| iTime | duration in millisecond of this frame. |
| Sint32 CRM64Pro::Sprite::getFrameTime | ( | Sint32 | iAnim, |
| Sint32 | iFrame, | ||
| Uint16 * | iTime ) |
Get the frame time duration.
| iAnim | the animation state (high-state + low-state) or animation number. Use -1 for current animation. |
| iFrame | frame number from 0 to getFrameNumber(). Use -1 for current frame. |
| iTime | duration in milliseconds of this frame. |
| Sint32 CRM64Pro::Sprite::setPosition | ( | float | fX, |
| float | fY, | ||
| Sint32 | iInterpolation = 0 ) |
Set the sprite position.
| fX | sprite X position. |
| fY | sprite Y position. |
| iInterpolation | 0 (default) sets position immediately on next render(). Any other value enables progressive interpolated position change using Advanced Graphics methods. |
| Sint32 CRM64Pro::Sprite::getPosition | ( | float * | fX, |
| float * | fY ) |
Get the sprite position.
| fX | a float pointer filled in with X sprite position. If nullptr is passed, the method ignores the retrieving of this value. |
| fY | a float pointer filled in with Y sprite position. If nullptr is passed, the method ignores the retrieving of this value. |
| Sint32 CRM64Pro::Sprite::render | ( | Sint32 | idRes = 0 | ) |
Render the sprite.
| idRes | a valid screen or image handle. Default uses the default screen. |
| Sint32 CRM64Pro::Sprite::save | ( | const string & | sFileCDC | ) |
Save the sprite to a CDC file.
The associated image will also be saved to the same CDC file.
| sFileCDC | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
| Sint32 CRM64Pro::Sprite::save | ( | Sint32 | idCDC | ) |
Save the sprite to a CDC file.
The associated image will also be saved to the same CDC file.
| idCDC | CDC id. |
| Sint32 CRM64Pro::SpriteMgr::info | ( | Sint32 | iMode = 0 | ) |
| Sint32 CRM64Pro::SpriteMgr::create | ( | const string & | sName, |
| Uint32 | iVersion = 10 ) |
Create a new sprite.
Creates an empty sprite (no image). Use Sprite::assignImage() to assign an image.
| sName | The sprite name (e.g. 'mySprite'). Must be unique, max 64 characters. |
| iVersion | Sprite version. 10 means v1.0 (only version supported). Default v1.0. |
| Sint32 CRM64Pro::SpriteMgr::close | ( | Sint32 | idSprite | ) |
Close and destroy a sprite.
| idSprite | 0 for closing all sprites, or specific Sprite id. Stand-alone and child sprites can be closed; parent sprites cannot while they have children. |
| Sint32 CRM64Pro::SpriteMgr::getNum | ( | ) | const |
Get number of loaded objects.
| Sint32 CRM64Pro::SpriteMgr::setName | ( | Sint32 | idSprite, |
| const string & | sName ) |
| Sprite * CRM64Pro::SpriteMgr::get | ( | Sint32 | idSprite | ) |
Get a pointer to the sprite using its handler.
| idSprite | Sprite id. |
| Sint32 CRM64Pro::SpriteMgr::child | ( | Sint32 | idSprite | ) |
Create a child sprite dependent on the provided one (the parent).
A child sprite uses parent's attributes and creates a child image for different attributes.
| idSprite | parent Sprite id. If the provided sprite is a child, the request is redirected to its parent. |
| Sint32 CRM64Pro::SpriteMgr::load | ( | const string & | sFileCDC, |
| const string & | sName ) |
Load a sprite stored in a CDC file.
| sFileCDC | string containing [directory]+filename. Directory separators '\' and '/' are supported. |
| sName | string with the sprite name (max 64 characters). If already exists, creates a child instead. |
| Sint32 CRM64Pro::SpriteMgr::load | ( | const Sint32 | idCDC, |
| const string & | sName ) |
Load a sprite stored in a CDC file.
| idCDC | CDC id. |
| sName | string with the sprite name (max 64 characters). If already exists, creates a child instead. |
| Sint32 CRM64Pro::SpriteMgr::remove | ( | const Sint32 | idCDC, |
| const string & | sName ) |
Remove a sprite stored in a CDC file.
| idCDC | CDC id. |
| sName | string with the sprite name (maximum size of 64 characters). |