File: cs_224.html

package info (click to toggle)
crystalspace 0.94-20020412-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 62,276 kB
  • ctags: 52,843
  • sloc: cpp: 274,783; ansic: 6,608; perl: 6,276; objc: 3,952; asm: 2,942; python: 2,354; php: 542; pascal: 530; sh: 430; makefile: 370; awk: 193
file content (269 lines) | stat: -rw-r--r-- 11,367 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created by texi2html 1.64 -->
<!-- 
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
 
-->
<HTML>
<HEAD>
<TITLE>Crystal Space: The Sprite Action Interface</TITLE>

<META NAME="description" CONTENT="Crystal Space: The Sprite Action Interface">
<META NAME="keywords" CONTENT="Crystal Space: The Sprite Action Interface">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64">

</HEAD>

<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">

<A NAME="SEC551"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_223.html#SEC546"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_225.html#SEC557"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_220.html#SEC543"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_221.html#SEC544"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_226.html#SEC559"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<HR SIZE=1>
<H3> 7.10.3 The Sprite Action Interface </H3>
<!--docid::SEC551::-->
<P>

<EM>Written by Michael Voase,
<A HREF="mailto:mvoase@midcoast.com.au">mvoase@midcoast.com.au</A>.</EM>
</P><P>

<A NAME="SEC552"></A>
<H4> Interfacing with the Sprite </H4>
<!--docid::SEC552::-->
<P>

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 <A HREF="cs_134.html#SEC297">6.4 Shared Class Facility (SCF)</A>.  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.
</P><P>

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

<TABLE><tr><td>&nbsp;</td><td class=example><pre>iMeshFactoryWrapper *fwrap = Engine-&#62;FindMeshFactory("name");
iMeshObjectFactory *fact = fwrap-&#62;GetMeshObjectFactory();

iMeshWrapper *mwrap = Engine-&#62;FindMeshObject("name");
iMeshObject *mesh = mwrap-&#62;GetMeshObject();
</pre></td></tr></table></P><P>

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,
</P><P>

<UL>
<LI>
<CODE>iSpriteFrame</CODE> 
<LI>
<CODE>iSpriteAction</CODE> 
<LI>
<CODE>iSprite3DFactoryState</CODE> 
<LI>
<CODE>iSprite3DState</CODE>. 
</UL>
<P>

The declarations for these interfaces can be found in 
`<TT>CS/include/imesh/sprite3d.h</TT>'. The first two interfaces can be obtained
by using the <CODE>FindFrame()</CODE> and <CODE>FindAction()</CODE> methods  in the 
`<SAMP>iSprite3dFactoryState</SAMP>' interface (described later).
The third interface can be obtained by querying the `<SAMP>iMeshObjectFactory</SAMP>'
interface. The `<SAMP>iSprite3DState</SAMP>' interface can be obtained from the
`<SAMP>iMeshObject</SAMP>' 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:
</P><P>

<TABLE><tr><td>&nbsp;</td><td class=example><pre>iSprite3dFactoryState *fstat =
  SCF_QUERY_INTERFACE(fact, iSprite3dFactoryState);
iSprite3DState *stat =
  SCF_QUERY_INTERFACE(mesh, iSprite3DState);
</pre></td></tr></table></P><P>

The `<SAMP>mesh</SAMP>' and `<SAMP>fact</SAMP>' 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 `<SAMP>iSprite3DState</SAMP>' or `<SAMP>iSprite3DFactoryState</SAMP>' interfaces
since they are adequately documented elsewhere.  Only methods which are
relevant to frame animation are treated here.
</P><P>

<A NAME="SEC553"></A>
<H4> <CODE>iSpriteFrame</CODE> </H4>
<!--docid::SEC553::-->
<P>

Current version: 0.0.2
</P><P>

<DL COMPACT>
<DT><CODE>void SetName(char const*)</CODE>
<DD>Set the name of this frame.
<DT><CODE>char const* GetName()</CODE>
<DD>Return the name of this frame
<DT><CODE>int GetAnmIndex()</CODE>
<DD>Returns the index of the first vertex used in this frame.  The vertex list is
stored in the sprite factory.
<DT><CODE>int GetTexIndex()</CODE>
<DD>Returns the index to the first texel used in this frame.  The texel list is
stored in the sprite factory.
</DL>
<P>

<A NAME="SEC554"></A>
<H4> <CODE>iSpriteAction</CODE> </H4>
<!--docid::SEC554::-->
<P>

Current version: 0.0.1
</P><P>

<DL COMPACT>
<DT><CODE>void SetName(char const*)</CODE>
<DD>Set the name of this action.
<DT><CODE>char const* GetName() const</CODE>
<DD>Return the name of this action.
<DT><CODE>int GetFrameCount()</CODE>
<DD>Get the total number of frames in this animation.
<DT><CODE>iSpriteFrame* GetFrame(int)</CODE>
<DD>Returns frame specified by input argument.
<DT><CODE>iSpriteFrame* GetNextFrame()</CODE>
<DD>Returns the next frame in the sequence.
<DT><CODE>int GetFrameDelay(int)</CODE>
<DD>Returns the duration of frame specified by input argument.
<DT><CODE>void AddFrame(iSpriteFrame* frame, int time)</CODE>
<DD>Adds the frame given by `<SAMP>frame</SAMP>' to this action
and set the duration to `<SAMP>time</SAMP>' 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.
</DL>
<P>

<A NAME="SEC555"></A>
<H4> <CODE>iSprite3DFactoryState</CODE> </H4>
<!--docid::SEC555::-->
<P>

Current version: 0.0.2
</P><P>

<DL COMPACT>
<DT><CODE>void AddVertices(int number)</CODE>
<DD>Adds `<SAMP>number</SAMP>' vertices to <STRONG>all</STRONG> frames
in this sprite factory. The all is emphasised so that you are aware
that the actual number of vertices created is `<SAMP>number</SAMP>' multiplied
by the number of frames. This is done to satisfy the requirement that
all frames must be of an equal size.
<DT><CODE>iSpriteFrame* AddFrame()</CODE>
<DD>Creates a new frame on the spirte 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 `<SAMP>iSpriteFrame</SAMP>' interface to operate on the frame.
<DT><CODE>iSpriteFrame* FindFrame(const char* title)</CODE>
<DD>Finds the frame named `<SAMP>title</SAMP>' in this sprite
factory and returns a pointer the frame.
<DT><CODE>int GetFrameCount()</CODE>
<DD>Returns the number of frames in this sprite factory.
<DT><CODE>iSpriteFrame* GetFrame(int index) const</CODE>
<DD>Returns a pointer to frame `<SAMP>index</SAMP>'. This
frame is part of the list of frames stored in this sprite factory.
<DT><CODE>iSpriteAction* AddAction()</CODE>
<DD>Create a new action and return a pointer to the action.
Once you have obtained the action, you will then be using the 
`<SAMP>iSpriteAction</SAMP>' interface to modify this action.
<DT><CODE>iSpriteAction* FindAction(const char* title) const</CODE>
<DD>Returns a pointer to the action named `<SAMP>title</SAMP>'.
<DT><CODE>iSpriteAction* GetFirstAction() const</CODE>
<DD>Returns a pointer to the first action in this sprite factory.
<DT><CODE>int GetActionCount() const</CODE>
<DD>Returns the number of actions stored in this sprite factory.
<DT><CODE>iSpriteAction* GetAction(int index) const</CODE>
<DD>Returns a pointer to action number `<SAMP>index</SAMP>'
<DT><CODE>void EnableTweening(bool flag)</CODE>
<DD>Enables or disables tweening on this sprite factory
depending on `<SAMP>flag</SAMP>'. 
<DT><CODE>bool IsTweeningEnabled()</CODE>
<DD>Returns the current setting for tweening on this sprite factory.
</DL>
<P>

<A NAME="SEC556"></A>
<H4> <CODE>iSprite3DState</CODE> </H4>
<!--docid::SEC556::-->
<P>

Current version: 0.0.4
</P><P>

<DL COMPACT>
<DT><CODE>void SetFrame(int index)</CODE>
<DD>Sets this sprite to frame number `<SAMP>index</SAMP>' in the
action current applied to this sprite.
<DT><CODE>int GetCurFrame() const</CODE>
<DD>Returns the index number of the current frame in the
current action applied to this sprite.
<DT><CODE>int GetFrameCount() const</CODE>
<DD>Returns the number of frames in the current action
applied to this sprite.
<DT><CODE>bool SetAction(const char *title)</CODE>
<DD>Set the current action of this sprite to the action
named `<SAMP>title</SAMP>'. Returns a flag indicating if the operation was
successful or not.
<DT><CODE>iSpriteAction* GetCurAction() const</CODE>
<DD>Returns a pointer to the current action applied to this sprite.
<DT><CODE>EnableTweening(bool flag)</CODE>
<DD>Description: Enables or disables tweeing on this sprite according
to `<SAMP>flag</SAMP>'.
<DT><CODE>bool IsTweeningEnabled() const</CODE>
<DD>Returns a flag indicating if tweening is enabled for this sprite.
</DL>
<A NAME="Moving On"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_223.html#SEC546"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_225.html#SEC557"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_220.html#SEC543"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_221.html#SEC544"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_226.html#SEC559"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>  
<FONT SIZE="-1">
This document was generated

using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>

</BODY>
</HTML>