GAF Library
Generic Animation Format
 All Classes Functions Pages
GAFAnimatedObject.h
1 #pragma once
2 
3 #ifndef __GAF_ANIMATED_OBJECT_H__
4 #define __GAF_ANIMATED_OBJECT_H__
5 
6 #include "GAFAnimation.h"
7 #include "GAFCollections.h"
8 
9 #include "GAFDelegates.h"
10 
11 class GAFAnimation;
12 class GAFSprite;
13 class GAFAnimator;
14 class GAFAnimatedObject;
15 class GAFAsset;
16 
17 enum PCAnimationFPSType // Obsolete. Will be removed
18 {
19  kGAFAnimationFPSType_15 = 15,
20  kGAFAnimationFPSType_30 = 30,
21  kGAFAnimationFPSType_60 = 60
22 };
23 
24 enum GAFAnimatedObjectControlFlags
25 {
26  kGAFAnimatedObjectControl_None = 0,
27  // If specified, state of controlled object will be changed every frame (like it is by default) and then
28  // animatedObject:didDisplayFrameWithSubobject: will be called
29  kGAFAnimatedObjectControl_ApplyState = 1 << 0
30 };
31 
32 
33 class GAFAnimatedObject : public cocos2d::Layer, public GAFAnimation
34 {
35 protected:
37 private:
38  GAFAsset * _asset;
39 
40  SubObjects_t m_subObjects;
41  SubObjects_t m_masks;
42 
43  int m_stencilLayer;
44 
45  CaptureObjects_t m_capturedObjects;
46  bool _animationsSelectorScheduled;
47  GAFFramePlayedDelegate * _framePlayedDelegate;
48  GAFAnimatedObjectControlDelegate * _controlDelegate;
49 
50  cocos2d::SpriteBatchNode* m_batch;
51 
52  int numberOfGlobalFramesForOneAnimationFrame();
53  int _extraFramesCounter;
54  PCAnimationFPSType _FPSType; // Obsolete. Will be removed
55  int m_fps;
56 
57  void _updateStencilLayer(int newLayer);
58 public:
60  static GAFAnimatedObject * create(GAFAsset * anAsset);
61  static GAFAnimatedObject * createAndRun(const std::string& gafPath, bool looped = false);
62 
63  bool init(GAFAsset * anAsset);
64  void processAnimations(float dt);
65  cocos2d::Vect pupilCoordinatesWithXSemiaxis(float anXSemiaxis, float anYSemiaxis, cocos2d::Vect aCenter, cocos2d::Vect anExternalPoint);
66  void removeAllSubObjects();
67 
68  void instantiateObject(const AnimationObjects_t& objs, const AnimationMasks_t& masks);
69 
70  void setSubobjectsVisible(bool visible);
71 
72  const SubObjects_t& getSubojects() const;
73  const SubObjects_t& getMasks() const;
74 
75  void animatorDidPlayedFrame(GAFAnimator * anAnimator, int aFrameNo);
76 
77  virtual void start();
78  virtual void stop();
79  virtual void processAnimation();
86  bool captureControlOverSubobjectNamed(const char * aName, GAFAnimatedObjectControlFlags aControlFlags);
88  void releaseControlOverSubobjectNamed(const char * aName);
89 
90  void setFramePlayedDelegate(GAFFramePlayedDelegate * delegate);
91  void setControlDelegate(GAFAnimatedObjectControlDelegate * delegate);
92  cocos2d::Rect realBoundingBoxForCurrentFrame();
93 
95  GAFSprite * subObjectForInnerObjectId(unsigned int anInnerObjectId);
97  unsigned int objectIdByObjectName(const std::string& aName);
98 
99  cocos2d::Sprite* renderCurrentFrameToTexture(bool usePOTTextures = false);
100 
101  void realizeFrame(cocos2d::Node* out, int frameIndex);
102 
104  void setStencilLayer(int newLayer);
105 
107  void incStencilLayer();
108 
110  void decStencilLayer();
111 
113  int getStencilLayer() const;
114 
116  void enableBatching(bool value);
117 
118 }; // GAFAnimatedObject
119 
120 #endif // __GAF_ANIMATED_OBJECT_H__
Definition: GAFAnimatedObject.h:33
Definition: GAFSprite.h:23
Definition: GAFAsset.h:18
Definition: GAFDelegates.h:43
void decStencilLayer()
0 means all masked pixels will be marked as 1 and so on
Definition: GAFAnimatedObject.cpp:716
void setStencilLayer(int newLayer)
0 means all masked pixels will be marked as 1 and so on
Definition: GAFAnimatedObject.cpp:704
unsigned int objectIdByObjectName(const std::string &aName)
Returns object id by it name, defined in NamedParts.
Definition: GAFAnimatedObject.cpp:116
Definition: GAFDelegates.h:33
void enableBatching(bool value)
Experimental feature, will work only for single textured objects without masks. Still glitches...
Definition: GAFAnimatedObject.cpp:727
bool captureControlOverSubobjectNamed(const char *aName, GAFAnimatedObjectControlFlags aControlFlags)
Definition: GAFAnimatedObject.cpp:240
GAFSprite * subObjectForInnerObjectId(unsigned int anInnerObjectId)
Returns subobject by it id.
Definition: GAFAnimatedObject.cpp:351
void releaseControlOverSubobjectNamed(const char *aName)
Releases control over subobject captured earlier.
Definition: GAFAnimatedObject.cpp:259
void incStencilLayer()
0 means all masked pixels will be marked as 1 and so on
Definition: GAFAnimatedObject.cpp:710
int getStencilLayer() const
0 means all masked pixels will be marked as 1 and so on
Definition: GAFAnimatedObject.cpp:722
Definition: GAFAnimation.h:19