CCParticleSystemQuad.h 5.5 KB

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