ParticleSystemModule.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // ParticleSystemModule.hpp
  3. // ParticleTool
  4. //
  5. // Created by zhuangyou on 2019/5/9.
  6. //
  7. #ifndef RUParticleSystemModule_hpp
  8. #define RUParticleSystemModule_hpp
  9. #include "cocos2d.h"
  10. #include "RUDefine.h"
  11. NS_RU_BEGIN
  12. enum class SheetMode{
  13. GRIDE = 0,
  14. PLIST, //TODO
  15. };
  16. enum class SheetAnimationMode{
  17. WHOLESHEET,
  18. SINGLEROW,//TODO
  19. };
  20. enum class ParticleSystemModuleFlag
  21. {
  22. SHAPE = 1<< 0,
  23. TEXTURE_SHEET = 1<< 1,
  24. TRAIL = 1<< 2,
  25. NOISE = 1 << 3,
  26. };
  27. class ParticleSystemModule{
  28. public:
  29. ParticleSystemModule(){}
  30. ~ParticleSystemModule(){}
  31. void setEnable(bool isEnable) { enable = isEnable; onEnable(enable);}
  32. bool isEnable() { return enable;}
  33. virtual void init(){}
  34. virtual void onEnable(bool isEnable){}
  35. virtual void update(){}
  36. void setParticleSystem(ParticleSystem* particleSystem){_particleSystem = particleSystem;}
  37. ParticleSystem* getParitcleSystem(){return _particleSystem;}
  38. ParticleSystemModuleFlag getFlag(){return _flag;}
  39. protected:
  40. ParticleSystem* _particleSystem;
  41. bool enable;
  42. ParticleSystemModuleFlag _flag;
  43. };
  44. class TextureSheetAnimationModule :public ParticleSystemModule
  45. {
  46. public:
  47. TextureSheetAnimationModule():_startFrame(0),_frameCount(1),_useRandomStartFrame(false)
  48. {_mode = SheetMode::GRIDE;_animationMode = SheetAnimationMode::WHOLESHEET;_flag = ParticleSystemModuleFlag::TEXTURE_SHEET;_fileName = "";}
  49. ~TextureSheetAnimationModule(){}
  50. Vec2 getTiles(){ return _tiles;}
  51. void setTiles(const Vec2 &tiles) { _tiles = Vec2(tiles.x,tiles.y);}
  52. void setStartFrame(int frame) {_startFrame = frame;}
  53. int getFrameCount() { return _frameCount; }
  54. void setFrameCount(int framCount) { _frameCount = framCount; }
  55. void setUseRandomStartFrame(bool useRnd) { _useRandomStartFrame = useRnd;}
  56. bool isUseRandomStartFrame() { return _useRandomStartFrame;}
  57. void setCycles(int cycles) {_cycles = cycles;}
  58. void setFlipX(int flip) { _flipX = flip;}
  59. void setFlipY(int flip) { _flipY = flip;}
  60. void setTexture(Texture2D* texture) { _texture = texture;}
  61. float getTileWidth() {return _tileWidth;}
  62. float getTileHeight() {return _tileHeight;}
  63. SpriteFrame* generateSpriteFrame(int index);
  64. void setFileName(string fileName) {_fileName = fileName;};
  65. virtual void init(){}
  66. virtual void onEnable(bool isEnable);
  67. // virtual void update();
  68. private:
  69. Vec2 _tiles;
  70. int _startFrame;
  71. int _frameCount;
  72. int _cycles;
  73. int _flipX;
  74. int _flipY;
  75. float _tileWidth;
  76. float _tileHeight;
  77. bool _useRandomStartFrame;
  78. SheetMode _mode;
  79. SheetAnimationMode _animationMode;
  80. Texture2D* _texture;
  81. string _fileName;//在大图中的名字
  82. };
  83. class NoiseModule :public ParticleSystemModule
  84. {
  85. public:
  86. NoiseModule(){
  87. _bCheapGradient = true;//目前可以忽略
  88. _frequency = 1.0;
  89. _octaves = 2;
  90. _lacunarity = 2.0;
  91. _persistence = 0.5;
  92. _strength = 1.0;
  93. _flag = ParticleSystemModuleFlag::NOISE;
  94. }
  95. ~NoiseModule(){}
  96. void setFrequency(float freq) { _frequency = freq;}
  97. float getFrequency() {return _frequency;}
  98. void setOctaves(unsigned int oct) {_octaves = oct;}
  99. int getOctaves() {return _octaves;}
  100. void setLacunarity(float lac) { _lacunarity = lac;}
  101. float getLacunarity() {return _lacunarity;}
  102. void setPersistence(float pers) { _persistence = pers;}
  103. float getPersistence() {return _persistence;}
  104. void setStrength(float strength){ _strength = strength; }
  105. float getStrength() {return _strength;}
  106. virtual void init(){}
  107. virtual void onEnable(bool isEnable);
  108. // virtual void update();
  109. private:
  110. private:
  111. bool _bCheapGradient;
  112. float _frequency;
  113. unsigned int _octaves;
  114. float _lacunarity;
  115. float _persistence;
  116. float _strength;
  117. };
  118. NS_RU_END
  119. #endif /* RUParticleSystemModule_hpp */