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 "layers_scenes_transitions_nodes/CCLayer.h"
7 #include "GAFAnimation.h"
8 #include <vector>
9 #include <string>
10 
11 class GAFAnimation;
12 class GAFSprite;
13 class GAFAnimator;
14 class GAFAnimatedObject;
15 class GAFAsset;
16 
17 namespace cocos2d
18 {
19  class CCDictionary;
20  class CCArray;
21  class CCString;
22 }
23 
24 using namespace cocos2d;
25 
26 enum PCAnimationFPSType
27 {
28  kGAFAnimationFPSType_15 = 15,
29  kGAFAnimationFPSType_30 = 30,
30  kGAFAnimationFPSType_60 = 60
31 };
32 
33 enum GAFAnimatedObjectControlFlags
34 {
35  kGAFAnimatedObjectControl_None = 0,
36  // If specified, state of controlled object will be changed every frame (like it is by default) and then
37  // animatedObject:didDisplayFrameWithSubobject: will be called
38  kGAFAnimatedObjectControl_ApplyState = 1 << 0
39 };
40 
45 
47 {
48 public:
52 
53  virtual void onFramePlayed(GAFAnimatedObject * object, int frame);
54 };
55 
57 {
58 public:
59  virtual void onFrameDisplayed(GAFAnimatedObject * object, GAFSprite * subobject);
60 };
61 
62 class GAFAnimatedObject : public CCLayer, public GAFAnimation
63 {
64 public:
66  static GAFAnimatedObject * create(GAFAsset * anAsset);
67  static GAFAnimatedObject * create(const char * jsonPath);
68  static GAFAnimatedObject * createAndRun(const char * jsonPath, bool looped = false);
69 
70  bool init(GAFAsset * anAsset);
71  void processAnimations(float dt);
72  CCPoint pupilCoordinatesWithXSemiaxis(float anXSemiaxis, float anYSemiaxis, CCPoint aCenter, CCPoint anExternalPoint);
73  GAFSprite * subObjectForInnerObjectId(CCString * anInnerObjectId);
74  void removeAllSubObjects();
75  void addSubObjectsUsingAnimationObjectsDictionary(CCDictionary * anAnimationObjects, CCDictionary * anAnimationMasks, CCArray * anAnimationFrames);
76  void setSubobjectsVisible(bool visible);
77  CCDictionary * subObjects();
78  CCDictionary * masks();
79  void animatorDidPlayedFrame(GAFAnimator * anAnimator, int aFrameNo);
81  GAFSprite * subobjectByName(const char * name);
82  // call this function only if you really know what you do
83  GAFSprite * subobjectByRawName(const char * name);
84  virtual void start();
85  virtual void stop();
86  virtual void processAnimation();
93  bool captureControlOverSubobjectNamed(const char * aName, GAFAnimatedObjectControlFlags aControlFlags);
95  void releaseControlOverSubobjectNamed(const char * aName);
96 
97  void setFramePlayedDelegate(GAFFramePlayedDelegate * delegate);
98  void setControlDelegate(GAFAnimatedObjectControlDelegate * delegate);
99  CCRect realBoundingBoxForCurrentFrame();
100 protected:
102  GAFSprite * subObjectForInnerObjectId(const char * anInnerObjectId);
103  std::string objectIdByObjectName(const char * aName);
104 
105 private:
106  GAFAsset * _asset;
107  CCDictionary * _subObjects;
108  CCDictionary * _masks;
109  CCDictionary * _capturedObjects;
110  bool _animationsSelectorScheduled;
111  GAFFramePlayedDelegate * _framePlayedDelegate;
112  GAFAnimatedObjectControlDelegate * _controlDelegate;
113 
114  int numberOfGlobalFramesForOneAnimationFrame();
115  int _extraFramesCounter;
116  PCAnimationFPSType _FPSType;
117 
118 }; // GAFAnimatedObject
119 
120 #endif // __GAF_ANIMATED_OBJECT_H__
Definition: GAFAnimatedObject.h:62
Definition: GAFSprite.h:29
Definition: GAFAsset.h:21
Definition: GAFAnimatedObject.h:56
Definition: GAFAnimatedObject.h:46
Definition: GAFAnimation.h:35