CCParticleSystemQuad.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2009 Leonardo Kasperavičius
  4. Copyright (c) 2010-2012 cocos2d-x.org
  5. Copyright (c) 2011 Zynga Inc.
  6. Copyright (c) 2013-2016 Chukong Technologies Inc.
  7. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  8. http://www.cocos2d-x.org
  9. Permission is hereby granted, free of charge, to any person obtaining a copy
  10. of this software and associated documentation files (the "Software"), to deal
  11. in the Software without restriction, including without limitation the rights
  12. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. copies of the Software, and to permit persons to whom the Software is
  14. furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in
  16. all copies or substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. THE SOFTWARE.
  24. ****************************************************************************/
  25. #ifndef __CC_PARTICLE_SYSTEM_QUAD_H__
  26. #define __CC_PARTICLE_SYSTEM_QUAD_H__
  27. #include "2d/CCParticleSystem.h"
  28. #include "renderer/CCQuadCommand.h"
  29. NS_CC_BEGIN
  30. class SpriteFrame;
  31. class EventCustom;
  32. /**
  33. * @addtogroup _2d
  34. * @{
  35. */
  36. /** @class ParticleSystemQuad
  37. * @brief ParticleSystemQuad is a subclass of ParticleSystem.
  38. It includes all the features of ParticleSystem.
  39. Special features and Limitations:
  40. - Particle size can be any float number.
  41. - The system can be scaled.
  42. - The particles can be rotated.
  43. - It supports subrects.
  44. - It supports batched rendering since 1.1.
  45. @since v0.8
  46. @js NA
  47. */
  48. class CC_DLL ParticleSystemQuad : public ParticleSystem
  49. {
  50. public:
  51. /** Creates a Particle Emitter.
  52. *
  53. * @return An autoreleased ParticleSystemQuad object.
  54. */
  55. static ParticleSystemQuad * create();
  56. /** Creates a Particle Emitter with a number of particles.
  57. *
  58. * @param numberOfParticles A given number of particles.
  59. * @return An autoreleased ParticleSystemQuad object.
  60. */
  61. static ParticleSystemQuad * createWithTotalParticles(int numberOfParticles);
  62. /** Creates an initializes a ParticleSystemQuad from a plist file.
  63. This plist files can be created manually or with Particle Designer.
  64. *
  65. * @param filename Particle plist file name.
  66. * @return An autoreleased ParticleSystemQuad object.
  67. */
  68. static ParticleSystemQuad * create(const std::string& filename);
  69. /** Creates a Particle Emitter with a dictionary.
  70. *
  71. * @param dictionary Particle dictionary.
  72. * @return An autoreleased ParticleSystemQuad object.
  73. */
  74. static ParticleSystemQuad * create(ValueMap &dictionary);
  75. /** Sets a new SpriteFrame as particle.
  76. WARNING: this method is experimental. Use setTextureWithRect instead.
  77. *
  78. * @param spriteFrame A given sprite frame as particle texture.
  79. @since v0.99.4
  80. */
  81. void setDisplayFrame(SpriteFrame *spriteFrame);
  82. /** Sets a new texture with a rect. The rect is in Points.
  83. @since v0.99.4
  84. * @js NA
  85. * @lua NA
  86. *
  87. * @param texture A given texture.
  88. 8 @param rect A given rect, in points.
  89. */
  90. void setTextureWithRect(Texture2D *texture, const Rect& rect);
  91. /** Listen the event that renderer was recreated on Android/WP8.
  92. * @js NA
  93. * @lua NA
  94. *
  95. * @param event the event that renderer was recreated on Android/WP8.
  96. */
  97. void listenRendererRecreated(EventCustom* event);
  98. /**
  99. * @js NA
  100. * @lua NA
  101. */
  102. virtual void setTexture(Texture2D* texture) override;
  103. /**
  104. * @js NA
  105. * @lua NA
  106. */
  107. virtual void updateParticleQuads() override;
  108. /**
  109. * @js NA
  110. * @lua NA
  111. */
  112. virtual void postStep() override;
  113. /**
  114. * @js NA
  115. * @lua NA
  116. */
  117. virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
  118. /**
  119. * @js NA
  120. * @lua NA
  121. */
  122. virtual void setBatchNode(ParticleBatchNode* batchNode) override;
  123. /**
  124. * @js NA
  125. * @lua NA
  126. */
  127. virtual void setTotalParticles(int tp) override;
  128. virtual std::string getDescription() const override;
  129. CC_CONSTRUCTOR_ACCESS:
  130. /**
  131. * @js ctor
  132. */
  133. ParticleSystemQuad();
  134. /**
  135. * @js NA
  136. * @lua NA
  137. */
  138. virtual ~ParticleSystemQuad();
  139. // Overrides
  140. /**
  141. * @js NA
  142. * @lua NA
  143. */
  144. virtual bool initWithTotalParticles(int numberOfParticles) override;
  145. protected:
  146. /** initializes the indices for the vertices*/
  147. void initIndices();
  148. /** initializes the texture with a rectangle measured Points */
  149. void initTexCoordsWithRect(const Rect& rect);
  150. /** Updates texture coords */
  151. void updateTexCoords();
  152. void setupVBOandVAO();
  153. void setupVBO();
  154. bool allocMemory();
  155. V3F_C4B_T2F_Quad *_quads; // quads to be rendered
  156. GLushort *_indices; // indices
  157. GLuint _VAOname;
  158. GLuint _buffersVBO[2]; //0: vertex 1: indices
  159. QuadCommand _quadCommand; // quad command
  160. private:
  161. CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystemQuad);
  162. };
  163. // end of _2d group
  164. /// @}
  165. NS_CC_END
  166. #endif //__CC_PARTICLE_SYSTEM_QUAD_H__