2011-03-19 10:07:16 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2009 Leonardo Kasperavičius
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-06-08 14:11:48 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2011-03-19 10:07:16 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CC_PARTICLE_SYSTEM_QUAD_H__
|
|
|
|
#define __CC_PARTICLE_SYSTEM_QUAD_H__
|
|
|
|
|
2010-12-28 11:55:34 +08:00
|
|
|
#include "CCParticleSystem.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/renderer/CCQuadCommand.h"
|
2011-03-19 10:07:16 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2010-12-28 11:55:34 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class SpriteFrame;
|
2013-12-31 10:54:37 +08:00
|
|
|
class EventCustom;
|
2010-12-28 11:55:34 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup particle_nodes
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** @brief ParticleSystemQuad is a subclass of ParticleSystem
|
2010-12-28 11:55:34 +08:00
|
|
|
|
|
|
|
It includes all the features of ParticleSystem.
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
Special features and Limitations:
|
2010-12-28 11:55:34 +08:00
|
|
|
- Particle size can be any float number.
|
|
|
|
- The system can be scaled
|
|
|
|
- The particles can be rotated
|
|
|
|
- It supports subrects
|
2012-06-08 14:11:48 +08:00
|
|
|
- It supports batched rendering since 1.1
|
2010-12-28 11:55:34 +08:00
|
|
|
@since v0.8
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL ParticleSystemQuad : public ParticleSystem
|
2010-12-28 11:55:34 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-06-14 16:27:47 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
/** creates a Particle Emitter */
|
|
|
|
static ParticleSystemQuad * create();
|
|
|
|
/** creates a Particle Emitter with a number of particles */
|
2013-11-15 08:21:49 +08:00
|
|
|
static ParticleSystemQuad * createWithTotalParticles(int numberOfParticles);
|
2013-06-20 14:13:12 +08:00
|
|
|
/** creates an initializes a ParticleSystemQuad from a plist file.
|
2013-07-18 07:56:19 +08:00
|
|
|
This plist files can be created manually or with Particle Designer:
|
|
|
|
*/
|
2013-11-15 08:21:49 +08:00
|
|
|
static ParticleSystemQuad * create(const std::string& filename);
|
2010-12-28 11:55:34 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** Sets a new SpriteFrame as particle.
|
2013-08-01 16:39:42 +08:00
|
|
|
WARNING: this method is experimental. Use setTextureWithRect instead.
|
2012-04-19 14:35:52 +08:00
|
|
|
@since v0.99.4
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
void setDisplayFrame(SpriteFrame *spriteFrame);
|
2010-12-28 11:55:34 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
/** Sets a new texture with a rect. The rect is in Points.
|
2013-09-13 11:41:20 +08:00
|
|
|
@since v0.99.4
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
void setTextureWithRect(Texture2D *texture, const Rect& rect);
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2012-04-24 15:02:18 +08:00
|
|
|
/** listen the event that coming to foreground on Android
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2012-04-24 15:02:18 +08:00
|
|
|
*/
|
2013-12-31 10:54:37 +08:00
|
|
|
void listenBackToForeground(EventCustom* event);
|
2012-06-02 07:38:43 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setTexture(Texture2D* texture) override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-04-15 18:08:29 +08:00
|
|
|
virtual void updateQuadWithParticle(tParticle* particle, const Vector2& newPosition) override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void postStep() override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-04-08 22:07:35 +08:00
|
|
|
virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) override;
|
2013-12-03 04:13:05 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setBatchNode(ParticleBatchNode* batchNode) override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-09-08 11:26:38 +08:00
|
|
|
virtual void setTotalParticles(int tp) override;
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2013-12-13 06:30:22 +08:00
|
|
|
virtual std::string getDescription() const override;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-15 08:21:49 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
|
|
|
ParticleSystemQuad();
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~ParticleSystemQuad();
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
// Overrides
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual bool initWithTotalParticles(int numberOfParticles) override;
|
2013-11-15 08:21:49 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2013-11-15 08:21:49 +08:00
|
|
|
/** initializes the indices for the vertices*/
|
|
|
|
void initIndices();
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
/** initializes the texture with a rectangle measured Points */
|
|
|
|
void initTexCoordsWithRect(const Rect& rect);
|
2014-01-03 18:15:56 +08:00
|
|
|
|
2014-02-13 10:33:57 +08:00
|
|
|
/** Updates texture coords */
|
|
|
|
void updateTexCoords();
|
2013-11-15 08:21:49 +08:00
|
|
|
|
2012-04-13 17:24:50 +08:00
|
|
|
void setupVBOandVAO();
|
|
|
|
void setupVBO();
|
2012-04-19 14:35:52 +08:00
|
|
|
bool allocMemory();
|
2013-11-15 08:21:49 +08:00
|
|
|
|
2013-07-23 18:26:26 +08:00
|
|
|
V3F_C4B_T2F_Quad *_quads; // quads to be rendered
|
2014-03-01 08:19:27 +08:00
|
|
|
GLushort *_indices; // indices
|
|
|
|
GLuint _VAOname;
|
|
|
|
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
|
|
|
|
|
|
|
QuadCommand _quadCommand; // quad command
|
2013-11-15 08:21:49 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystemQuad);
|
2010-12-28 11:55:34 +08:00
|
|
|
};
|
2011-03-19 10:07:16 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of particle_nodes group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2011-03-19 10:07:16 +08:00
|
|
|
|
|
|
|
#endif //__CC_PARTICLE_SYSTEM_QUAD_H__
|
|
|
|
|