CCParticleSystemQuadLoader.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /****************************************************************************
  2. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #include "editor-support/cocosbuilder/CCParticleSystemQuadLoader.h"
  21. using namespace cocos2d;
  22. #define PROPERTY_EMITERMODE "emitterMode"
  23. #define PROPERTY_POSVAR "posVar"
  24. #define PROPERTY_EMISSIONRATE "emissionRate"
  25. #define PROPERTY_DURATION "duration"
  26. #define PROPERTY_TOTALPARTICLES "totalParticles"
  27. #define PROPERTY_LIFE "life"
  28. #define PROPERTY_STARTSIZE "startSize"
  29. #define PROPERTY_ENDSIZE "endSize"
  30. #define PROPERTY_STARTSPIN "startSpin"
  31. #define PROPERTY_ENDSPIN "endSpin"
  32. #define PROPERTY_ANGLE "angle"
  33. #define PROPERTY_STARTCOLOR "startColor"
  34. #define PROPERTY_ENDCOLOR "endColor"
  35. #define PROPERTY_BLENDFUNC "blendFunc"
  36. #define PROPERTY_GRAVITY "gravity"
  37. #define PROPERTY_SPEED "speed"
  38. #define PROPERTY_TANGENTIALACCEL "tangentialAccel"
  39. #define PROPERTY_RADIALACCEL "radialAccel"
  40. #define PROPERTY_TEXTURE "texture"
  41. #define PROPERTY_STARTRADIUS "startRadius"
  42. #define PROPERTY_ENDRADIUS "endRadius"
  43. #define PROPERTY_ROTATEPERSECOND "rotatePerSecond"
  44. namespace cocosbuilder {
  45. void ParticleSystemQuadLoader::onHandlePropTypeIntegerLabeled(Node * pNode, Node * pParent, const char * pPropertyName, int pIntegerLabeled, CCBReader * ccbReader) {
  46. if(strcmp(pPropertyName, PROPERTY_EMITERMODE) == 0) {
  47. ((ParticleSystemQuad *)pNode)->setEmitterMode((ParticleSystem::Mode)pIntegerLabeled);
  48. } else {
  49. NodeLoader::onHandlePropTypeIntegerLabeled(pNode, pParent, pPropertyName, pIntegerLabeled, ccbReader);
  50. }
  51. }
  52. void ParticleSystemQuadLoader::onHandlePropTypePoint(Node * pNode, Node * pParent, const char * pPropertyName, Vec2 pPoint, CCBReader * ccbReader) {
  53. if(strcmp(pPropertyName, PROPERTY_POSVAR) == 0) {
  54. ((ParticleSystemQuad *)pNode)->setPosVar(pPoint);
  55. } else if(strcmp(pPropertyName, PROPERTY_GRAVITY) == 0) {
  56. ((ParticleSystemQuad *)pNode)->setGravity(pPoint);
  57. } else {
  58. NodeLoader::onHandlePropTypePoint(pNode, pParent, pPropertyName, pPoint, ccbReader);
  59. }
  60. }
  61. void ParticleSystemQuadLoader::onHandlePropTypeFloat(Node * pNode, Node * pParent, const char * pPropertyName, float pFloat, CCBReader * ccbReader) {
  62. if(strcmp(pPropertyName, PROPERTY_EMISSIONRATE) == 0) {
  63. ((ParticleSystemQuad *)pNode)->setEmissionRate(pFloat);
  64. } else if(strcmp(pPropertyName, PROPERTY_DURATION) == 0) {
  65. ((ParticleSystemQuad *)pNode)->setDuration(pFloat);
  66. } else {
  67. NodeLoader::onHandlePropTypeFloat(pNode, pParent, pPropertyName, pFloat, ccbReader);
  68. }
  69. }
  70. void ParticleSystemQuadLoader::onHandlePropTypeInteger(Node * pNode, Node * pParent, const char * pPropertyName, int pInteger, CCBReader * ccbReader) {
  71. if(strcmp(pPropertyName, PROPERTY_TOTALPARTICLES) == 0) {
  72. ((ParticleSystemQuad *)pNode)->setTotalParticles(pInteger);
  73. } else {
  74. NodeLoader::onHandlePropTypeInteger(pNode, pParent, pPropertyName, pInteger, ccbReader);
  75. }
  76. }
  77. void ParticleSystemQuadLoader::onHandlePropTypeFloatVar(Node * pNode, Node * pParent, const char * pPropertyName, float * pFloatVar, CCBReader * ccbReader) {
  78. if(strcmp(pPropertyName, PROPERTY_LIFE) == 0) {
  79. ((ParticleSystemQuad *)pNode)->setLife(pFloatVar[0]);
  80. ((ParticleSystemQuad *)pNode)->setLifeVar(pFloatVar[1]);
  81. } else if(strcmp(pPropertyName, PROPERTY_STARTSIZE) == 0) {
  82. ((ParticleSystemQuad *)pNode)->setStartSize(pFloatVar[0]);
  83. ((ParticleSystemQuad *)pNode)->setStartSizeVar(pFloatVar[1]);
  84. } else if(strcmp(pPropertyName, PROPERTY_ENDSIZE) == 0) {
  85. ((ParticleSystemQuad *)pNode)->setEndSize(pFloatVar[0]);
  86. ((ParticleSystemQuad *)pNode)->setEndSizeVar(pFloatVar[1]);
  87. } else if(strcmp(pPropertyName, PROPERTY_STARTSPIN) == 0) {
  88. ((ParticleSystemQuad *)pNode)->setStartSpin(pFloatVar[0]);
  89. ((ParticleSystemQuad *)pNode)->setStartSpinVar(pFloatVar[1]);
  90. } else if(strcmp(pPropertyName, PROPERTY_ENDSPIN) == 0) {
  91. ((ParticleSystemQuad *)pNode)->setEndSpin(pFloatVar[0]);
  92. ((ParticleSystemQuad *)pNode)->setEndSpinVar(pFloatVar[1]);
  93. } else if(strcmp(pPropertyName, PROPERTY_ANGLE) == 0) {
  94. ((ParticleSystemQuad *)pNode)->setAngle(pFloatVar[0]);
  95. ((ParticleSystemQuad *)pNode)->setAngleVar(pFloatVar[1]);
  96. } else if(strcmp(pPropertyName, PROPERTY_SPEED) == 0) {
  97. ((ParticleSystemQuad *)pNode)->setSpeed(pFloatVar[0]);
  98. ((ParticleSystemQuad *)pNode)->setSpeedVar(pFloatVar[1]);
  99. } else if(strcmp(pPropertyName, PROPERTY_TANGENTIALACCEL) == 0) {
  100. ((ParticleSystemQuad *)pNode)->setTangentialAccel(pFloatVar[0]);
  101. ((ParticleSystemQuad *)pNode)->setTangentialAccelVar(pFloatVar[1]);
  102. } else if(strcmp(pPropertyName, PROPERTY_RADIALACCEL) == 0) {
  103. ((ParticleSystemQuad *)pNode)->setRadialAccel(pFloatVar[0]);
  104. ((ParticleSystemQuad *)pNode)->setRadialAccelVar(pFloatVar[1]);
  105. } else if(strcmp(pPropertyName, PROPERTY_STARTRADIUS) == 0) {
  106. ((ParticleSystemQuad *)pNode)->setStartRadius(pFloatVar[0]);
  107. ((ParticleSystemQuad *)pNode)->setStartRadiusVar(pFloatVar[1]);
  108. } else if(strcmp(pPropertyName, PROPERTY_ENDRADIUS) == 0) {
  109. ((ParticleSystemQuad *)pNode)->setEndRadius(pFloatVar[0]);
  110. ((ParticleSystemQuad *)pNode)->setEndRadiusVar(pFloatVar[1]);
  111. } else if(strcmp(pPropertyName, PROPERTY_ROTATEPERSECOND) == 0) {
  112. ((ParticleSystemQuad *)pNode)->setRotatePerSecond(pFloatVar[0]);
  113. ((ParticleSystemQuad *)pNode)->setRotatePerSecondVar(pFloatVar[1]);
  114. } else {
  115. NodeLoader::onHandlePropTypeFloatVar(pNode, pParent, pPropertyName, pFloatVar, ccbReader);
  116. }
  117. }
  118. void ParticleSystemQuadLoader::onHandlePropTypeColor4FVar(Node * pNode, Node * pParent, const char * pPropertyName, Color4F * pColor4FVar, CCBReader * ccbReader) {
  119. if(strcmp(pPropertyName, PROPERTY_STARTCOLOR) == 0) {
  120. ((ParticleSystemQuad *)pNode)->setStartColor(pColor4FVar[0]);
  121. ((ParticleSystemQuad *)pNode)->setStartColorVar(pColor4FVar[1]);
  122. } else if(strcmp(pPropertyName, PROPERTY_ENDCOLOR) == 0) {
  123. ((ParticleSystemQuad *)pNode)->setEndColor(pColor4FVar[0]);
  124. ((ParticleSystemQuad *)pNode)->setEndColorVar(pColor4FVar[1]);
  125. } else {
  126. NodeLoader::onHandlePropTypeColor4FVar(pNode, pParent, pPropertyName, pColor4FVar, ccbReader);
  127. }
  128. }
  129. void ParticleSystemQuadLoader::onHandlePropTypeBlendFunc(Node * pNode, Node * pParent, const char * pPropertyName, BlendFunc pBlendFunc, CCBReader * ccbReader) {
  130. if(strcmp(pPropertyName, PROPERTY_BLENDFUNC) == 0) {
  131. ((ParticleSystemQuad *)pNode)->setBlendFunc(pBlendFunc);
  132. } else {
  133. NodeLoader::onHandlePropTypeBlendFunc(pNode, pParent, pPropertyName, pBlendFunc, ccbReader);
  134. }
  135. }
  136. void ParticleSystemQuadLoader::onHandlePropTypeTexture(Node * pNode, Node * pParent, const char * pPropertyName, Texture2D * pTexture2D, CCBReader * ccbReader) {
  137. if(strcmp(pPropertyName, PROPERTY_TEXTURE) == 0) {
  138. static_cast<ParticleSystemQuad*>(pNode)->setTexture(pTexture2D);
  139. if(pTexture2D)
  140. {
  141. static_cast<ParticleSystemQuad*>(pNode)->setBlendAdditive(true);
  142. }
  143. } else {
  144. NodeLoader::onHandlePropTypeTexture(pNode, pParent, pPropertyName, pTexture2D, ccbReader);
  145. }
  146. }
  147. }