Blame view

ios/Runner/Wowgame/Classes/game_toy/ToySpriteAnimator.h 6.58 KB
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
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
  //
  //  ToySpriteAnimator.h
  //  SteveMaggieCpp
  //
  //  Created by Katarzyna Kalinowska-Górska on 01.06.2017.
  //
  //
  
  #ifndef ToySpriteAnimator_h
  #define ToySpriteAnimator_h
  
  #include "json/document.h"
  #include "cocos2d.h"
  #include <vector>
  
  class ToySpriteAnimator : public cocos2d::Ref {
    
      public:
      
          // tags for RepeatForever animations
          static const int RF_ANIMATION_TAG_BASE = 10;
      
          static const int RF_ANIMATION_TAG_BOUNCE_ANIMATION = 1;
          static const int RF_ANIMATION_TAG_FLOAT_ANIMATION = 2;
          static const int RF_ANIMATION_TAG_WIND_TUG_ANIMATION = 3;
          static const int RF_ANIMATION_TAG_FRAME_ANIMATION = 4;
          static const int RF_ANIMATION_TAG_JUMP_ANIMATION = 5;
          static const int RF_ANIMATION_TAG_SCALE_UP_DOWN_ANIMATION = 6;
          static const int RF_ANIMATION_TAG_ROTATE_FOREVER_ANIMATION = 7;
          static const int RF_ANIMATION_TAG_TRAIN_RUN_FOREVER_ANIMATION = 8;
      
          static const int RF_ANIMATION_TAG_RANGE_MIN = 11;
          static const int RF_ANIMATION_TAG_RANGE_MAX = 17;
      
          static void runAnimationForName(std::string animationName, std::vector<cocos2d::Node*> sprites, const rapidjson::Value* params);
      
          // standard animations
      
          // only supported for one sprite
          static void frameAnimation(cocos2d::Node* sprite, std::vector<std::string> imageFileArray, std::string folder = "");
      
          // only supported for sprites
          static void clipToAnimation(std::vector<cocos2d::Node*> sprites, std::vector<float> durations, std::vector<cocos2d::Rect> textureRects);
      
          static void fadeInAnimation(std::vector<cocos2d::Node*> sprites);
          static void fadeOutAnimation(std::vector<cocos2d::Node*> sprites);
          static void moveToAnimation(std::vector<cocos2d::Node*> sprites, float duration, std::vector<cocos2d::Point> newPositions, std::string easeOption = "");
          static void moveByAnimation(std::vector<cocos2d::Node*> sprites, float duration, cocos2d::Vec2 deltaPosition, std::string easeOption = "");
          static void rotateByAnimation(std::vector<cocos2d::Node*> sprites, float duration, float rotationAngle, std::string easeOption = "");
          static void bezierByAnimation(std::vector<cocos2d::Node*> sprites, std::vector<std::vector<float>> bezierPathsDeltaXs, std::vector<std::vector<float>> bezierPathsDeltaYs, std::vector<float> durations);
          static void simpleRotateAnimation(std::vector<cocos2d::Node*> sprites, std::vector<float> delays, std::vector<cocos2d::Point> animationAnchorPoints, std::vector<float> rotationAngles, std::vector<float> rotationDurations, std::vector<int> repeatTimes);
      
      
          // fancy animations
          static void trainRunForeverAnimation(std::vector<cocos2d::Node*> sprites, float lapDuration);
          static void crazyRotateAnimation(std::vector<cocos2d::Node*> sprites);
          static void fullRotateAnimation(std::vector<cocos2d::Node*> sprites, bool crazy, std::vector<float> durations);
          static void rotateForeverAnimation(std::vector<cocos2d::Node*> sprites, std::vector<float> oneLapDurations);
          static void scaleUpDownAnimation(std::vector<cocos2d::Node*> sprites, float upperScale = 1.1, float scaleUpDownDuration = 0.4, int times = 0);
          static void jumpAnimation(std::vector<cocos2d::Node*> sprites, std::vector<float> durations, std::vector<cocos2d::Point> deltas, std::vector<float> heights);
          static void jumpAnimation(std::vector<cocos2d::Node*> sprites, std::vector<float> durations, std::vector<cocos2d::Point> deltas, std::vector<float> heights, std::vector<int> jumps);
          static void floatAnimation(std::vector<cocos2d::Node*> sprites, std::vector<float> delays, std::vector<std::vector<float>> dxRanges, std::vector<std::vector<float>> dyRanges, float totalBezierTime = 2.4);
          static void windTugAnimation(std::vector<cocos2d::Node*> sprites, std::vector<float> skewAnglesX, std::vector<float> skewAnglesY);
          static void windTugAnimationWithRotation(std::vector<cocos2d::Node*> sprites, std::vector<float> skewAnglesX, std::vector<float> skewAnglesY, std::vector<float> delays = std::vector<float>());
          static void bounceAnimation(std::vector<cocos2d::Node*> sprites, std::vector<float> delays = std::vector<float>(), std::vector<float> rotationDurations = std::vector<float>(), std::vector<float> rotationAngles = std::vector<float>(),std::vector<float> wholeDurations = std::vector<float>(), bool roundUp = false);
          static void swipeAnimation(std::vector<cocos2d::Node*> sprites, float delayConst = 0.05, cocos2d::Point animationAnchorPoint = cocos2d::Point(0.5, 1), int rotationDir = 1, cocos2d::Vec2 moveDir = cocos2d::Vec2(-1,-1));
          static void sinusoidalMoveAnimation(std::vector<cocos2d::Node*> sprites, float duration, std::vector<cocos2d::Point> moveDestinations, std::vector<float> amplitudes, std::string easeOption = "");
      
          // rf actions handling
          static std::string mapTagToRFAction(int tag);
          static void restoreRFAction(cocos2d::Node* sprite, int actionTag);
      
          static void cleanUpAnimationData(cocos2d::Node* node);
      
          class FloatAnimationData : public cocos2d::Ref {
              public:
                  float delay;
                  std::vector<float> dxRange;
                  std::vector<float> dyRange;
                  float bezierTime;
          };
      
          class BounceAnimationData: public cocos2d::Ref {
              public:
                  float delay;
                  float rotationAngle;
                  float rotationDuration;
                  float wholeDuration;
                  bool roundUp;
          };
      
          class AnimationUserData : public cocos2d::Ref {
              public:
                  FloatAnimationData* floatAnimationData;
                  BounceAnimationData* bounceAnimationData;
                  AnimationUserData(){
                      floatAnimationData = NULL;
                      bounceAnimationData = NULL;
                  }
                  ~AnimationUserData(){
                      if(floatAnimationData){
                          delete floatAnimationData;
                      }
                      if(bounceAnimationData){
                          delete bounceAnimationData;
                      }
                  }
                  //can add mapping tag->animationdata
          };
      
      protected:
      
          static cocos2d::Action* actionWithEaseOption(cocos2d::ActionInterval* action, std::string easeOption = "");
          static void singleSpriteFloatAnimation(cocos2d::Node* sprite, float delay, std::vector<float> dxRange, std::vector<float> dyRange, float totalBezierTime = 2.4);
  };
  
  #endif /* ToySpriteAnimator_h */