-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimation.h
514 lines (463 loc) · 17.2 KB
/
Animation.h
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
#pragma once
///
// Headers
///
#include <SFML/Graphics.h>
/// @brief Differents possible states of playing a animation
/// (Default, LOOPED, REVERSED, FLIP_X, FLIP_Y)
enum State
{
/// @brief Default state
DEFAULT = 0x01,
/// @brief Set animation in loop
LOOPED = 0x02,
/// @brief Reverse the animation order
REVERSED = 0x04,
/// @brief Apply a horizontal flip
FLIP_X = 0x08,
/// @brief Apply a vertical flip
FLIP_Y = 0x10
};
typedef struct Animation Animation;
//////////////////////////////////////////////////////////////
/// @brief Create a new animation
///
/// @param _frameSize Size of a animation
///
/// @param _frameNb Number of frames
///
/// @return Animation object, or NULL if the animation cannot be create
//////////////////////////////////////////////////////////////
Animation* AnimationCreate(sfVector2u _frameSize, unsigned char _framesNb);
//////////////////////////////////////////////////////////////
/// @brief Set the flipping state of an Animation
///
/// @param _anim Animation object
///
//////////////////////////////////////////////////////////////
void AnimationSetFlipState(Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Update an animation
///
/// @param _anim Animation object
///
/// @param _dt Delta time
//////////////////////////////////////////////////////////////
void AnimationUpdate(Animation* _anim, float _dt);
//////////////////////////////////////////////////////////////
/// @brief Update an animation sprite with its current frame
///
/// @param _anim Animation object
//////////////////////////////////////////////////////////////
void AnimationFrameUpdate(Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Draw an animation
///
/// @param _window Render window object
///
/// @param _anim Animation object
///
/// @param _states Render states to use, NULL to use the default states
//////////////////////////////////////////////////////////////
void AnimationDraw(
const sfRenderWindow* _window,
const Animation* _anim,
const sfRenderStates* _states);
//draw anim on render tex
void AnimationDrawRenderTex(
const sfRenderTexture* _renderTex,
const Animation* _anim,
const sfRenderStates* _states);
//////////////////////////////////////////////////////////////
///
/// @brief Destroy an existing animation
///
/// @param _anim Animation object
///
//////////////////////////////////////////////////////////////
void AnimationSoftDestroy(Animation* _anim);
////////////////////////////////////////////////////////////
/// @brief Destroy an existing animation
///
/// @param _anim Animation object
///
////////////////////////////////////////////////////////////
void AnimationDestroy(Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Play an animation with the given state
///
/// @param _anim Animation object
///
/// @param _state State of the animation
//////////////////////////////////////////////////////////////
void AnimationPlay(Animation* _anim, unsigned char _state);
//////////////////////////////////////////////////////////////
/// @brief Define the actual frame of an animation
///
/// @param _anim Animation object
///
/// @param _frame Frame to set
//////////////////////////////////////////////////////////////
void AnimationSetFrame(Animation* _anim, unsigned char _frame);
//////////////////////////////////////////////////////////////
/// @brief Pause an animation
///
/// @param _anim Animation object
//////////////////////////////////////////////////////////////
void AnimationPause(Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Rewind an animation
///
/// @param _anim Animation object
//////////////////////////////////////////////////////////////
void AnimationRewind(Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Stop an animation (=pause and rewind)
///
/// @param _anim Animation object
//////////////////////////////////////////////////////////////
void AnimationStop(Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Get the duration of an animation
///
/// @param _anim Animation object
///
/// @return Duration of a animation
//////////////////////////////////////////////////////////////
float AnimationGetDuration(const Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Get the frame that an animation is playing
///
/// @param _anim Animation object
///
/// @return The frame that the animation is playing
//////////////////////////////////////////////////////////////
unsigned char AnimationGetCurrentFrame(const Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Tell if an animation is playing
///
/// @param _anim Animation object
///
/// @return State of playing of a animation
//////////////////////////////////////////////////////////////
sfBool AnimationIsPlaying(const Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Get the state of an animation
///
/// @param _anim Animation object
///
/// @return State of the animation
//////////////////////////////////////////////////////////////
unsigned char AnimationGetState(const Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Get the frame size of an animation
///
/// @param _anim Animation object
///
/// @return Size of a frame
//////////////////////////////////////////////////////////////
sfVector2u AnimationGetFrameSize(Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Get the frames number of an animation
///
/// @param _anim Animation object
///
/// @return Number of frame of the animation
//////////////////////////////////////////////////////////////
unsigned char AnimationGetFramesNb(Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Create a sprite sheet texture and set
///
/// @param _anim Animation object
///
/// @param _filename File name of the file containing sprite sheet
///
/// @param _structure Structure of the sprite sheet (horizontal, vertical, block)
///
/// @param _animationOffset Offset of the sprite sheet in the file,
/// NULL for no offset
///
/// @param _blockLength Width and height of the block sprite sheet,
/// NULL if sprite sheet is not a block
//////////////////////////////////////////////////////////////
void AnimationSetSpriteSheet(
Animation* _anim,
const char* _filename,
const char* _structure,
sfVector2u* _animationOffset,
sfVector2u* _blockLength);
//////////////////////////////////////////////////////////////
/// @brief Set the duration of an animation
///
/// @param _anim Animation object
///
/// @param _duration Duration of the animation
//////////////////////////////////////////////////////////////
void AnimationSetDuration(Animation* _anim, float _duration);
//////////////////////////////////////////////////////////////
/// @brief Set the frame rate of an animation
///
/// Calculate and set duration according to the wanted frame rate.
///
/// @param _anim Animation object
///
/// @param _framerate Frame rate of the animation
//////////////////////////////////////////////////////////////
void AnimationSetFramerate(Animation* _anim, float _framerate);
//////////////////////////////////////////////////////////////
/// @brief Set the sate of an animation
///
/// @param _anim Animation object
///
/// @param _state State for the animation
//////////////////////////////////////////////////////////////
void AnimationSetState(Animation* _anim, unsigned char _state);
//////////////////////////////////////////////////////////////
/// @brief Set the frame size of an animation
///
/// @param _anim Animation object
///
/// @param _frameSize Frame size of a animation
//////////////////////////////////////////////////////////////
void AnimationSetFrameSize(Animation* _anim, sfVector2u _frameSize);
//////////////////////////////////////////////////////////////
/// @brief Set the frames number of an animation
///
/// @param _anim Animation object
///
/// @param _framesNb Frames number
//////////////////////////////////////////////////////////////
void AnimationSetFramesNb(Animation* _anim, unsigned char _framesNb);
void AnimationSetClock(Animation* _anim, float _clock);
float AnimationGetClock(Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Get the frame rate of an animation
///
/// Calculate frame rate from the duration of the animation.
///
/// @param _anim Animation object
///
/// @return Frame rate of the animation
//////////////////////////////////////////////////////////////
float AnimationGetFramerate(Animation* _anim);
//////////////////////////////////////////////////////////////
/// @brief Get the sprite sheet texture of an animation
///
/// @param _anim Animation object
///
/// @return Sprite sheet texture of the animation
//////////////////////////////////////////////////////////////
Animation* AnimationSmartCopy(const Animation* _animation);
////////////////////////////////////////////////////////////
/// @brief Copy an existing animation
///
/// @param _animation Animation to copy
///
/// @return Copied object, NULL if the copy fail
///
////////////////////////////////////////////////////////////
Animation* AnimationCopy(const Animation* _animation);
////////////////////////////////////////////////////////////
/// @brief Set the position of an animation
///
/// This function completely overwrites the previous position.
/// See AnimationMove to apply an offset based on the previous position instead.
/// The default position of a animation Animation object is (0, 0).
///
/// @param _animation Animation object
/// @param _position New position
///
////////////////////////////////////////////////////////////
void AnimationSetPosition(Animation* _animation, sfVector2f _position);
////////////////////////////////////////////////////////////
/// @brief Set the orientation of an animation
///
/// This function completely overwrites the previous rotation.
/// See AnimationRotate to add an angle based on the previous rotation instead.
/// The default rotation of a sprite Sprite object is 0.
///
/// @param _animation Animation object
/// @param _angle New rotation, in degrees
///
////////////////////////////////////////////////////////////
void AnimationSetRotation(Animation* _animation, float _angle);
////////////////////////////////////////////////////////////
/// @brief Set the scale factors of an animation
///
/// This function completely overwrites the previous scale.
/// See AnimationScale to add a factor based on the previous scale instead.
/// The default scale of a sprite Sprite object is (1, 1).
///
/// @param _animation Animation object
/// @param _scale New scale factors
///
////////////////////////////////////////////////////////////
void AnimationSetScale(Animation* _animation, sfVector2f _scale);
////////////////////////////////////////////////////////////
/// @brief Get the position of an animation
///
/// @param _animation Animation object
///
/// @return Current position
///
////////////////////////////////////////////////////////////
sfVector2f AnimationGetPosition(const Animation* _animation);
////////////////////////////////////////////////////////////
/// @brief Get the orientation of an animation
///
/// The rotation is always in the range [0, 360].
///
/// @param _animation Animation object
///
/// @return Current rotation, in degrees
///
////////////////////////////////////////////////////////////
float AnimationGetRotation(const Animation* _animation);
////////////////////////////////////////////////////////////
/// @brief Get the current scale of an animation
///
/// @param _animation Animation object
///
/// @return Current scale factors
///
////////////////////////////////////////////////////////////
sfVector2f AnimationGetScale(const Animation* _animation);
////////////////////////////////////////////////////////////
/// @brief Get the local origin of an animation
///
/// @param _animation Animation object
///
/// @return Current origin
///
////////////////////////////////////////////////////////////
sfVector2f AnimationGetOrigin(const Animation* _animation);
////////////////////////////////////////////////////////////
/// @brief Move an animation by a given offset
///
/// This function adds to the current position of the object,
/// unlike AnimationSetPosition which overwrites it.
///
/// @param _animation Animation object
///
/// @param _offset Offset
///
////////////////////////////////////////////////////////////
void AnimationMove(Animation* _animation, sfVector2f _offset);
////////////////////////////////////////////////////////////
/// @brief Rotate an animation
///
/// This function adds to the current rotation of the object,
/// unlike AnimationSetRotation which overwrites it.
///
/// @param _animation Animation object
///
/// @param _angle Angle of rotation, in degrees
///
////////////////////////////////////////////////////////////
void AnimationRotate(Animation* _animation, float _angle);
////////////////////////////////////////////////////////////
/// @brief Scale an animation
///
/// This function multiplies the current scale of the object,
/// unlike AnimationSetScale which overwrites it.
///
/// @param _animation Animation object
///
/// @param _factors Scale factors
///
////////////////////////////////////////////////////////////
void AnimationScale(Animation* _animation, sfVector2f _factors);
////////////////////////////////////////////////////////////
/// @brief Get the combined transform of an animation
///
/// @param _animation Animation object
///
/// @return Transform combining the position/rotation/scale/origin of the object
///
////////////////////////////////////////////////////////////
sfTransform AnimationGetTransform(const Animation* _animation);
////////////////////////////////////////////////////////////
/// @brief Get the inverse of the combined transform of an animation
///
/// @param _animation Animation object
///
/// @return Inverse of the combined transformations applied to the object
///
////////////////////////////////////////////////////////////
sfTransform AnimationGetInverseTransform(const Animation* _animation);
////////////////////////////////////////////////////////////
/// @brief Set the global color of an animation
///
/// This color is modulated (multiplied) with the sprite's texture of the
/// animation. It can be used to colorize the animation, or change its global
/// opacity.
/// By default, the animation's color is opaque white.
///
/// @param _animation Animation object
///
/// @param _color New color of the sprite
///
////////////////////////////////////////////////////////////
void AnimationSetColor(Animation* _animation, sfColor _color);
////////////////////////////////////////////////////////////
/// @brief Get the source sprite sheet texture of an animation
///
/// If the animation has no source sprite sheet texture,
/// a NULL pointer is returned.
/// The returned pointer is const, which means that you can't
/// modify the sprite sheet texture when you retrieve it with this function.
///
/// @param _animation Animation object
///
/// @return Pointer to the animation's sprite sheet texture
///
////////////////////////////////////////////////////////////
const sfTexture* AnimationGetSpriteSheetTexture(const Animation* _animation);
////////////////////////////////////////////////////////////
/// @brief Get the global color of an animation
///
/// @param _animation Animation object
///
/// @return Global color of the sprite
///
////////////////////////////////////////////////////////////
sfColor AnimationGetColor(const Animation* _animation);
////////////////////////////////////////////////////////////
/// @brief Get the local bounding rectangle of an animation
///
/// The returned rectangle is in local coordinates, which means
/// that it ignores the transformations (translation, rotation,
/// scale, ...) that are applied to the entity.
/// In other words, this function returns the bounds of the
/// entity in the entity's coordinate system.
///
/// @param _animation Animation object
///
/// @return Local bounding rectangle of the entity
///
////////////////////////////////////////////////////////////
sfFloatRect AnimationGetLocalBounds(const Animation* _animation);
////////////////////////////////////////////////////////////
/// @brief Get the global bounding rectangle of an animation
///
/// The returned rectangle is in global coordinates, which means
/// that it takes in account the transformations (translation,
/// rotation, scale, ...) that are applied to the entity.
/// In other words, this function returns the bounds of the
/// sprite in the global 2D world's coordinate system.
///
/// @param _animation Animation object
///
/// @return Global bounding rectangle of the entity
///
////////////////////////////////////////////////////////////
sfFloatRect AnimationGetGlobalBounds(const Animation* _animation);
////////////////////////////////////////////////////////////
///
/// @brief Get the current frame of an animation
///
/// @param _animation Animation object
///
/// @return Current frame
////////////////////////////////////////////////////////////
sfIntRect AnimationGetTextureRect(const Animation* _animation);