CRM64Pro GDK  v0.94
A free cross-platform game development kit built on top of SDL 2.0
Classes | Macros | Functions
Sprite Manager

Classes

class  CRM64Pro::SpriteObj
 
class  CRM64Pro::SpriteMgr
 

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)   (x & 0xFF00)
 
#define SPR_GET_LOWSTATE(x)   (x & 0x00FF)
 
#define SPR_HOTSPOT_CENTER   0x0A000000
 
#define SPR_HOTSPOT_END   0x0B000000
 

Functions

Sint32 CRM64Pro::SpriteObj::info (Sint32 iMode=0)
 
Sint32 CRM64Pro::SpriteObj::getName (string &sName)
 
Uint32 CRM64Pro::SpriteObj::getID ()
 
Sint32 CRM64Pro::SpriteObj::assignImage (Sint32 idImage, Sint32 iOwnership=0)
 
Sint32 CRM64Pro::SpriteObj::getImage ()
 
Sint32 CRM64Pro::SpriteObj::setOffset (Sint32 iX, Sint32 iY)
 
Sint32 CRM64Pro::SpriteObj::getOffset (Sint32 *iX, Sint32 *iY)
 
Sint32 CRM64Pro::SpriteObj::pause ()
 
Sint32 CRM64Pro::SpriteObj::resume ()
 
Sint32 CRM64Pro::SpriteObj::status ()
 
Sint32 CRM64Pro::SpriteObj::setSpeed (float fSpeed)
 
Sint32 CRM64Pro::SpriteObj::getAnimNumber ()
 
Sint32 CRM64Pro::SpriteObj::getAnimCurrent ()
 
Sint32 CRM64Pro::SpriteObj::selectAnim (Sint32 iAnim)
 
Sint32 CRM64Pro::SpriteObj::setAnimType (Sint32 iAnim, Sint32 iType)
 
Sint32 CRM64Pro::SpriteObj::getAnimType (Sint32 iAnim, Sint32 *iType)
 
Sint32 CRM64Pro::SpriteObj::setAnimState (Sint32 iAnim, Sint32 iState)
 
Sint32 CRM64Pro::SpriteObj::getAnimState (Sint32 iAnim, Sint32 *iState)
 
Sint32 CRM64Pro::SpriteObj::setAnimHotSpot (Sint32 iAnim, Sint32 iHotX, Sint32 iHotY)
 
Sint32 CRM64Pro::SpriteObj::getAnimHotSpot (Sint32 iAnim, Sint32 *iHotX, Sint32 *iHotY)
 
Sint32 CRM64Pro::SpriteObj::setAnimRange (Sint32 iAnim, Sint32 iFrameStart, Sint32 iFrameEnd)
 
Sint32 CRM64Pro::SpriteObj::getAnimRange (Sint32 iAnim, Sint32 *iFrameStart, Sint32 *iFrameEnd)
 
Sint32 CRM64Pro::SpriteObj::getFrameNumber (Sint32 iAnim)
 
Sint32 CRM64Pro::SpriteObj::getFrameCurrent ()
 
Sint32 CRM64Pro::SpriteObj::selectFrame (Sint32 iAnim, Sint32 iFrame)
 
Sint32 CRM64Pro::SpriteObj::setFrameTime (Sint32 iAnim, Sint32 iFrame, Uint16 iTime)
 
Sint32 CRM64Pro::SpriteObj::getFrameTime (Sint32 iAnim, Sint32 iFrame, Uint16 *iTime)
 
Sint32 CRM64Pro::SpriteObj::setPosition (Sint32 iX, Sint32 iY, Sint32 iInterpolation=0)
 
Sint32 CRM64Pro::SpriteObj::getPosition (Sint32 *iX, Sint32 *iY)
 
Sint32 CRM64Pro::SpriteObj::render (Sint32 idRes=0)
 
Sint32 CRM64Pro::SpriteObj::save (const string &sFileCDC)
 
Sint32 CRM64Pro::SpriteObj::save (Sint32 idCDC)
 
Sint32 CRM64Pro::SpriteMgr::info (Sint32 iMode=0)
 
Sint32 CRM64Pro::SpriteMgr::create (const string &sName, Uint32 iVersion=10)
 
Sint32 CRM64Pro::SpriteMgr::close (Sint32 idSprite)
 
Sint32 CRM64Pro::SpriteMgr::getNum ()
 
Sint32 CRM64Pro::SpriteMgr::setName (Sint32 idSprite, const string &sName)
 
SpriteObj * CRM64Pro::SpriteMgr::get (Sint32 idSprite)
 
Sint32 CRM64Pro::SpriteMgr::child (Sint32 idSprite)
 
Sint32 CRM64Pro::SpriteMgr::load (const string &sFileCDC, const string &sName)
 
Sint32 CRM64Pro::SpriteMgr::load (const Sint32 idCDC, const string &sName)
 
Sint32 CRM64Pro::SpriteMgr::remove (const Sint32 idCDC, const string &sName)
 

Detailed Description

Sprites are a collection of smaller images of uniform and rectangular size contained on the image sprite sheet that can be animated.
The image sprite sheet has associated a specific logic that represents different animation states, types and frames with a time duration.

For the time being, there is only one version of the Sprite Object which is the v1.0 with the following features:

CRM64Pro_SpriteDetail.png
Sprite state and animations


With this manager, you can manage all common operations done in a sprite set.
There is a method for getting the Image id in order to get access to the Image object, for example, you can export the sprite image to an external file or modify the alpha modulation.
The storage layer(load() and save() methods) are using the CDC v1.x specification.

CRM64Pro_Sprite.png


This is an advance "cloning" manager: when loading from a CDC file a sprite which is already loaded/created (using the name as the key), it will create a new child sprite.
Only a single instance of the Sprite Manager exists which is created once Main is instantiated.
You can get a reference to this manager using Main::ISpriteMgr() method.

Note
The Sprite Manager is automatically released when Main::Terminate() is called.
At this time, if any resource is still loaded, it will be released avoding a resource leak.

Macro Definition Documentation

#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)    (x & 0xFF00)

Each state is a 16bit value, the high byte set the high-state which is defined by the GDK.
Use this macro for getting the sprite animation high-state. See above SPR_STATE_xx.

#define SPR_GET_LOWSTATE (   x)    (x & 0x00FF)

Each state is a 16bit value, the low byte set the low-state(up to 256) which can be defined by the user.
Use this macro for getting the sprite animation low-state.

#define SPR_HOTSPOT_CENTER   0x0A000000

Used with SpriteObj::setAnimHotSpot() to set as hotspot the frame_size/2.

#define SPR_HOTSPOT_END   0x0B000000

Used with SpriteObj::setAnimHotSpot() to set as hotspot the frame_size.

Function Documentation

Sint32 CRM64Pro::SpriteObj::info ( Sint32  iMode = 0)

Request Sprite object information.

For displaying the information, it uses the default log.

Parameters
iMode0 for standard output and 1 for extended output including frame times.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::getName ( string &  sName)

Get the name.

Parameters
sNamea string containing the sprite name.
Returns
0 on success or a negative error code on failure.
Uint32 CRM64Pro::SpriteObj::getID ( )

Get the ID.

Returns
the object ID.
Sint32 CRM64Pro::SpriteObj::assignImage ( Sint32  idImage,
Sint32  iOwnership = 0 
)

Assign an Image to this sprite.

It is used for loading an Image when the sprite is created with SpriteMgr::create().

Parameters
idImageImage id containing the sprite sheet.
iOwnership0 for creating our own copy of the image or any other integer for taking the ownership of the image, in this case, the image can not be already owned by other item.
By default it is set to 0.
Returns
0 on success or a negative error code on failure.
Note
The image name associated to this sprite will be internally modified: starts with the reserved character '#' + an internal code + the sprite name.
When re-assigning a new image, the old one will be closed.
Sint32 CRM64Pro::SpriteObj::getImage ( )

Get the assigned Image of this sprite.

Returns
greater than 0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::setOffset ( Sint32  iX,
Sint32  iY 
)

Set the sprite offsets for creating the animations and frames.

The conversion allows to have non-exact offset division, the remainder parts of the image will not be used.

Parameters
iXan integer with the offset X for creating the number of frames.
The assigned image width will be divided by this value for creating the frames.
In addition, a scanning process will look for frames and as soon as it finds an empty one (colorkey or alpha), it will set the last found frame as the end of this animation.
iYan integer with the offset Y for creating the number of animations and it also sets the frame's height.
The assigned image height will be divided by this value for creating the animations.
Returns
0 on success or a negative error code on failure.
Note
Start and end frames for each animation will be recreated by this method.
Sint32 CRM64Pro::SpriteObj::getOffset ( Sint32 *  iX,
Sint32 *  iY 
)

Get the sprite offsets (frames and animations).

Parameters
iXan integer pointer filled in with sprite offset X (width of each frame). If nullptr is passed, the method ignores the retrieving of this value.
iYan integer pointer filled in with sprite offset Y (height of each frame). If nullptr is passed, the method ignores the retrieving of this value.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::pause ( )

Pause the sprite animation.

Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::resume ( )

Resume from a previous paused sprite animation.

Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::status ( )

Get the sprite status.

Returns
C64_STATUS_ENABLEDsprite animation is enabled.
C64_STATUS_PAUSEDsprite animation is paused.
Sint32 CRM64Pro::SpriteObj::setSpeed ( float  fSpeed)

Set the sprite speed.

Parameters
fSpeedfloat number setting the relative speed,ex: 0.5 will be 50% slower.
By default it is set to 1.0.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::getAnimNumber ( )

Get number of animations.

Returns
number of animations for this sprite.
Sint32 CRM64Pro::SpriteObj::getAnimCurrent ( )

Get current animation number.

Returns
current animation or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::selectAnim ( Sint32  iAnim)

Select an animation by state or by number.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
Returns
0 on success or a negative error code on failure.
Note
When a new animation is selected, it tries to keep the current frame number.
Sint32 CRM64Pro::SpriteObj::setAnimType ( Sint32  iAnim,
Sint32  iType 
)

Set the animation type.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
iTypeAnimation type. Check SPR_TYPE_LOOP, SPR_TYPE_PINGPONG and SPR_TYPE_ONESHOT definition for further information.
Returns
0 on success or a negative error code on failure.
Note
Works on stand-alone and parent sprites, children can not change this attribute.
Sint32 CRM64Pro::SpriteObj::getAnimType ( Sint32  iAnim,
Sint32 *  iType 
)

Get the animation type.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
Use -1 for getting the type of current animation.
iTypean integer pointer filled in with the animation type (SPR_TYPE_LOOP, SPR_TYPE_PINGPONG or SPR_TYPE_ONESHOT).
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::setAnimState ( Sint32  iAnim,
Sint32  iState 
)

Set the animation state.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
iStateAnimation state (high-state + low-state).
Each high-state must has unique low-state values.
Returns
0 on success or a negative error code on failure.
Note
Works on stand-alone and parent sprites, children can not change this attribute.
Sint32 CRM64Pro::SpriteObj::getAnimState ( Sint32  iAnim,
Sint32 *  iState 
)

Get the animation state.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
Use -1 for getting the state of current animation.
iStatean integer pointer filled in with the animation state (high-state + low-state).
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::setAnimHotSpot ( Sint32  iAnim,
Sint32  iHotX,
Sint32  iHotY 
)

Set the animation hotspot.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
iHotXthe x hotspot position of the animation. You can set any value or SPR_HOTSPOT_CENTER and SPR_HOTSPOT_END defines.
iHotYthe y hotspot position of the animation. You can set any value or SPR_HOTSPOT_CENTER and SPR_HOTSPOT_END defines.
Returns
0 on success or a negative error code on failure.
Note
Works on stand-alone and parent sprites, children can not change this attribute.
Sint32 CRM64Pro::SpriteObj::getAnimHotSpot ( Sint32  iAnim,
Sint32 *  iHotX,
Sint32 *  iHotY 
)

Get the animation hotspot.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
Use -1 for getting the hotspot of current animation.
iHotXan integer pointer filled in with the X hotspot position. If nullptr is passed, the method ignores the retrieving of this value.
iHotYan integer pointer filled in with the Y hotspot position. If nullptr is passed, the method ignores the retrieving of this value.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::setAnimRange ( Sint32  iAnim,
Sint32  iFrameStart,
Sint32  iFrameEnd 
)

Set the animation frame range.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
iFrameStartan integer with the start frame number [0, number of frames). If -1 is passed, the method ignores the setting of this value.
iFrameEndan integer with the end frame number [0, number of frames). If -1 is passed, the method ignores the setting of this value.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::getAnimRange ( Sint32  iAnim,
Sint32 *  iFrameStart,
Sint32 *  iFrameEnd 
)

Get the animation frame range.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
Use -1 for getting the frame range of current animation.
iFrameStartan 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.
iFrameEndan 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.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::getFrameNumber ( Sint32  iAnim)

Get number of frames for the given animation.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
Use -1 for getting the frame number of current animation.
Returns
number of frames for the given animation.
Sint32 CRM64Pro::SpriteObj::getFrameCurrent ( )

Get current frame number for the given animation.

Returns
current frame or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::selectFrame ( Sint32  iAnim,
Sint32  iFrame 
)

Select a frame for the given animation.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
iFrameframe number from 0 to getFrameNumber() to be selected.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::setFrameTime ( Sint32  iAnim,
Sint32  iFrame,
Uint16  iTime 
)

Set the frame time duration.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
iFrameframe number from 0 to getFrameNumber() to be selected.
iTimeduration in millisecond of this frame.
Returns
0 on success or a negative error code on failure.
Note
Works on stand-alone and parent sprites, children can not change this attribute.
Sint32 CRM64Pro::SpriteObj::getFrameTime ( Sint32  iAnim,
Sint32  iFrame,
Uint16 *  iTime 
)

Get the frame time duration.

Parameters
iAnimthe animation state (high-state + low-state) or the animation number from 0 to getAnimNumber().
Use -1 for getting the current animation.
iFrameframe number from 0 to getFrameNumber() to be selected.
Use -1 for getting the current frame.
iTimeduration in millisecond of this frame.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::setPosition ( Sint32  iX,
Sint32  iY,
Sint32  iInterpolation = 0 
)

Set the sprite position.

Parameters
iXan integer with the sprite X position.
iYan integer with the sprite Y position.
iInterpolation0 for setting immediately the position on the next render()/renderEx() call.
Any other value will set a progressive and interpolated position change during next render()/renderEx() calls while using an Advanced Graphics method. The interpolation is calculated with the previous position.
By default, it is set to 0.
Returns
0 on success or a negative error code on failure.
Note
Due to the nature of interpolated position, under some specific scenarios, some graphics issues could happen.
For example, the first call for fixing a position should be without interpolation.
Sint32 CRM64Pro::SpriteObj::getPosition ( Sint32 *  iX,
Sint32 *  iY 
)

Get the sprite position.

Parameters
iXan integer pointer filled in with X sprite position. If nullptr is passed, the method ignores the retrieving of this value.
iYan integer pointer filled in with Y sprite position. If nullptr is passed, the method ignores the retrieving of this value.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::render ( Sint32  idRes = 0)

Render the sprite.

Parameters
idResa valid screen or image handle.
By default it tries to use the default screen.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteObj::save ( const string &  sFileCDC)

Save the sprite to a CDC file.

The associated image will also be saved in to the same CDC file.

Parameters
sFileCDCstring containing the [directory]+filename+[extension].
Directory separators '\' and '/' are supported.
Returns
0 or greater on success or a negative error code on failure.
Note
If the sprite already exists, it will be overwritten.
Can not save child sprites.
Sint32 CRM64Pro::SpriteObj::save ( Sint32  idCDC)

Save the sprite to a CDC file.

The associated image will also be saved in to the same CDC file.

Parameters
idCDCCDC id.
Returns
0 or greater on success or a negative error code on failure.
Note
If the sprite already exists, it will be overwritten.
If the sprite is a child, it will call the save method of its parent.
Sint32 CRM64Pro::SpriteMgr::info ( Sint32  iMode = 0)

Request Sprite Manager information.

For displaying the information, it uses the default log.

Parameters
iMode-1 for displaying only Manager information.
0 for displaying Manager and all Objects information. This is the default value.
idSprite for displaying Manager and given Sprite id information.
Returns
0 on success or a negative error code on failure.
Sint32 CRM64Pro::SpriteMgr::create ( const string &  sName,
Uint32  iVersion = 10 
)

Create a new sprite.

This method will create an empty sprite (no image assigned), use SpriteObj::assignImage() method for assigning the image.

Parameters
sNameThe name to give to the sprite e.g. 'mySprite'.
The object name must be unique and with a maximum size of 64 characters or will be truncated.
iVersionSprite version. 10 means 1.0 which is the only version supported (as of now).
v1.0 is set by default.
Returns
greater than 0 on success(the Sprite id) or a negative error code on failure.
Note
If the provided name already exists, it does nothing and return an error code.
Sint32 CRM64Pro::SpriteMgr::close ( Sint32  idSprite)

Close and destroy a sprite.

Parameters
idSprite0 for closing all sprites or the Sprite id.
Stand-alone and child sprites can be closed but parent ones, can not as they have at least one dependency(a child).
Returns
0 on success or a negative error code on failure.
Note
If you forget to close a Sprite, it will be automatically closed once the GDK is terminated.
Sint32 CRM64Pro::SpriteMgr::getNum ( )

Get number of loaded objects.

Returns
the number of sprites.
Sint32 CRM64Pro::SpriteMgr::setName ( Sint32  idSprite,
const string &  sName 
)

Change the object name.

Parameters
idSpriteSprite id.
sNameThe name to give to the sprite e.g. 'mySprite'.
The object name must be unique and with a maximum size of 64 characters or will be truncated.
Returns
0 on success or a negative error code on failure.
Note
The image name associated to this tile will be internally modified: starts with the reserved character '#' + an internal code + the sprite name.
SpriteObj * CRM64Pro::SpriteMgr::get ( Sint32  idSprite)

Get a pointer to the sprite using its handler.

Parameters
idSpriteSprite id.
Returns
nullptr the sprite was not found.
A pointer to the sprite object.
Sint32 CRM64Pro::SpriteMgr::child ( Sint32  idSprite)

Create a child sprite dependant on the provided one(the parent).

A child sprite uses the attributes of the parent and creates also a parent child image for having different attributes.

Parameters
idSpriteparent Sprite id.
If the provided sprite is a child, internally it will redirect this request to the parent in order to create the new child.
Returns
greater than 0 on success(the Sprite id) or a negative error code on failure.
Note
The child use the parent's name.
Sint32 CRM64Pro::SpriteMgr::load ( const string &  sFileCDC,
const string &  sName 
)

Load a sprite stored in a CDC file.

Parameters
sFileCDCstring containing the [directory]+filename.
Directory separators '\' and '/' are supported.
sNamestring with the sprite name (maximum size of 64 characters).
If the sprite is already created, this method will call child() for creating a child.
Returns
0 or greater on success(the Sprite id) or a negative error code on failure.
Sint32 CRM64Pro::SpriteMgr::load ( const Sint32  idCDC,
const string &  sName 
)

Load a sprite stored in a CDC file.

Parameters
idCDCCDC id.
sNamestring with the sprite name (maximum size of 64 characters).
If the sprite is already created, this method will call child() for creating a child.
Returns
greater than 0 on success(the Sprite id) or a negative error code on failure.
Sint32 CRM64Pro::SpriteMgr::remove ( const Sint32  idCDC,
const string &  sName 
)

Remove a sprite stored in a CDC file.

Parameters
idCDCCDC id.
sNamestring with the sprite name (maximum size of 64 characters).
Returns
greater than 0 on success or a negative error code on failure.
Note
The sprite must be closed before trying to remove it from the CDC.