RedreamAnim.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // RedreamAnim.h
  3. // redream_runtime
  4. //
  5. // Created by zhuge on 2023/1/17.
  6. //
  7. #ifndef RedreamAnim_h
  8. #define RedreamAnim_h
  9. #include "cocos2d.h"
  10. namespace redream {
  11. class REDKeyframe;
  12. class REDAnimationManager;
  13. class REDSequenceProperty;
  14. class RedreamAnim: public cocos2d::Ref {
  15. private:
  16. class PropKeyframes: public cocos2d::Ref {
  17. public:
  18. std::string propName;
  19. cocos2d::Vector<redream::REDKeyframe*> keyframes;
  20. };
  21. public:
  22. ~RedreamAnim();
  23. static RedreamAnim* createFromAnimFile(std::string filePath);
  24. bool init(const char* filePath);
  25. public:
  26. // 编辑
  27. void setStartPosition(cocos2d::Vec2 pos) { _startPosition = pos; }
  28. void setEndPosition(cocos2d::Vec2 pos) { _endPosition = pos; }
  29. float getDuration() { return _duration; }
  30. cocos2d::Action* getAction(); // autorelease
  31. private:
  32. REDAnimationManager* _loadAnimFile(const char* filePath);
  33. /// 給_propKeyframes初始化值
  34. /// @param animationManager 动画属性管理器
  35. /// @param node 唯一的动画节点
  36. /// @param seqNodeProps 该唯一节点的每个属性的动画关键帧
  37. void _initPropKeyframes(REDAnimationManager* animationManager, cocos2d::Node* node, cocos2d::Map<std::string, REDSequenceProperty*>& seqNodeProps);
  38. REDKeyframe* _createRedKeyframe(const cocos2d::Value& value, float atTime) const;
  39. Vec2 _getControlPoint(Vec2 A_start, Vec2 A_end, Vec2 A_control, Vec2 B_start, Vec2 B_end);
  40. Vec2 _valueToVec2(const cocos2d::Value& value);
  41. private:
  42. cocos2d::Vec2 _startPosition;
  43. cocos2d::Vec2 _endPosition;
  44. float _duration;
  45. cocos2d::Map<std::string, PropKeyframes*> _propKeyframes;
  46. };
  47. };
  48. #endif /* RedreamAnim_h */