[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.11.3 The Sprite Action Interface

Written by Michael Voase, mvoase@midcoast.com.au.

Interfacing with the Sprite

To begin this section, I am assuming here that you are aware of how to obtain the various interfaces from the engine. If not, read the documentation for SCF, the Shared Class Facility. See section 6.2 Shared Class Facility (SCF). I will be using terminology and concepts which are explained in that section. If you are only interested in writing map files for the engine then you can skip ahead to the next section.

Secondly, I am also presuming that you have loaded your sprite into the engine, and have access to that sprite via the `iEngine' interface. That implies that you have written a basic Crystal Space application (or are hacking up an existing application), and can access your sprite mesh factory using calls similar to the following:

 
iMeshFactoryWrapper *fwrap = Engine->FindMeshFactory("name");
iMeshObjectFactory *fact = fwrap->GetMeshObjectFactory();

iMeshWrapper *mwrap = Engine->FindMeshObject("name");
iMeshObject *mesh = mwrap->GetMeshObject();

With the name being the name of your mesh factory or object, respectively. There are four main interfaces that we will be dealing with in this section,

The declarations for these interfaces can be found in `CS/include/imesh/sprite3d.h'. The first two interfaces can be obtained by using the FindFrame() and FindAction() methods in the `iSprite3dFactoryState' interface (described later). The third interface can be obtained by querying the `iMeshObjectFactory' interface. The `iSprite3DState' interface can be obtained from the `iMeshObject' interface. The following is a summary of the methods in each interface and what they do. An example of obtaining the state interfaces is described below:

 
csRef<iSprite3dFactoryState> fstat =
  SCF_QUERY_INTERFACE(fact, iSprite3dFactoryState);
csRef<iSprite3DState> stat =
  SCF_QUERY_INTERFACE(mesh, iSprite3DState);

The `mesh' and `fact' variables are the ones mentioned earlier in this chapter. The following is summary of the methods and interface that are useful to the sprite animator during production. This summary does not fully document the `iSprite3DState' or `iSprite3DFactoryState' interfaces since they are adequately documented elsewhere. Only methods which are relevant to frame animation are treated here.

iSpriteFrame

Current version: 0.0.2

void SetName(char const*)
Set the name of this frame.
char const* GetName()
Return the name of this frame
int GetAnmIndex()
Returns the index of the first vertex used in this frame. The vertex list is stored in the sprite factory.
int GetTexIndex()
Returns the index to the first texel used in this frame. The texel list is stored in the sprite factory.

iSpriteAction

Current version: 0.0.1

void SetName(char const*)
Set the name of this action.
char const* GetName() const
Return the name of this action.
int GetFrameCount()
Get the total number of frames in this animation.
iSpriteFrame* GetFrame(int)
Returns frame specified by input argument.
iSpriteFrame* GetNextFrame()
Returns the next frame in the sequence.
int GetFrameDelay(int)
Returns the duration of frame specified by input argument.
void AddFrame(iSpriteFrame* frame, int time)
Adds the frame given by `frame' to this action and set the duration to `time' milliseconds. This method is used by the loader to add frames to an action. If you want to "roll your own", you will be using this interface to create your own actions. The frame must already be present in the frame list held by the sprite factory that this action came from.

iSprite3DFactoryState

Current version: 0.0.2

void AddVertices(int number)
Adds `number' vertices to all frames in this sprite factory. The all is emphasized so that you are aware that the actual number of vertices created is `number' multiplied by the number of frames. This is done to satisfy the requirement that all frames must be of an equal size.
iSpriteFrame* AddFrame()
Creates a new frame on the sprite frame list and returns a pointer to the newly created frame. The loader uses this method to load frames into a sprite. For each new frame added, an additional bank of vertices and texels is created for the new frame. Once you have this frame, you will then be using the `iSpriteFrame' interface to operate on the frame.
iSpriteFrame* FindFrame(const char* title)
Finds the frame named `title' in this sprite factory and returns a pointer the frame.
int GetFrameCount()
Returns the number of frames in this sprite factory.
iSpriteFrame* GetFrame(int index) const
Returns a pointer to frame `index'. This frame is part of the list of frames stored in this sprite factory.
iSpriteAction* AddAction()
Create a new action and return a pointer to the action. Once you have obtained the action, you will then be using the `iSpriteAction' interface to modify this action.
iSpriteAction* FindAction(const char* title) const
Returns a pointer to the action named `title'.
iSpriteAction* GetFirstAction() const
Returns a pointer to the first action in this sprite factory.
int GetActionCount() const
Returns the number of actions stored in this sprite factory.
iSpriteAction* GetAction(int index) const
Returns a pointer to action number `index'
void EnableTweening(bool flag)
Enables or disables tweening on this sprite factory depending on `flag'.
bool IsTweeningEnabled()
Returns the current setting for tweening on this sprite factory.

iSprite3DState

Current version: 0.0.4

void SetFrame(int index)
Sets this sprite to frame number `index' in the action current applied to this sprite.
int GetCurFrame() const
Returns the index number of the current frame in the current action applied to this sprite.
int GetFrameCount() const
Returns the number of frames in the current action applied to this sprite.
bool SetAction(const char *title)
Set the current action of this sprite to the action named `title'. Returns a flag indicating if the operation was successful or not.
iSpriteAction* GetCurAction() const
Returns a pointer to the current action applied to this sprite.
EnableTweening(bool flag)
Description: Enables or disables tweening on this sprite according to `flag'.
bool IsTweeningEnabled() const
Returns a flag indicating if tweening is enabled for this sprite.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated using texi2html