diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index bd4bef3599..ab14d1e8e4 100644 --- a/cocos/2d/CCParticleSystemQuad.cpp +++ b/cocos/2d/CCParticleSystemQuad.cpp @@ -200,6 +200,16 @@ void ParticleSystemQuad::initTexCoordsWithRect(const Rect& pointRect) quads[i].tr.texCoords.v = top; } } + +void ParticleSystemQuad::updateTexCoords() +{ + if (_texture) + { + const Size& s = _texture->getContentSize(); + initTexCoordsWithRect(Rect(0, 0, s.width, s.height)); + } +} + void ParticleSystemQuad::setTextureWithRect(Texture2D *texture, const Rect& rect) { // Only update the texture if is different from the current one @@ -210,11 +220,13 @@ void ParticleSystemQuad::setTextureWithRect(Texture2D *texture, const Rect& rect this->initTexCoordsWithRect(rect); } + void ParticleSystemQuad::setTexture(Texture2D* texture) { const Size& s = texture->getContentSize(); this->setTextureWithRect(texture, Rect(0, 0, s.width, s.height)); } + void ParticleSystemQuad::setDisplayFrame(SpriteFrame *spriteFrame) { CCASSERT(spriteFrame->getOffsetInPixels().equals(Point::ZERO), @@ -468,11 +480,10 @@ void ParticleSystemQuad::setTotalParticles(int tp) _indices = indicesNew; // Clear the memory - // XXX: Bug? If the quads are cleared, then drawing doesn't work... WHY??? XXX memset(_particles, 0, particlesSize); memset(_quads, 0, quadsSize); memset(_indices, 0, indicesSize); - + _allocatedParticles = tp; } else @@ -506,12 +517,17 @@ void ParticleSystemQuad::setTotalParticles(int tp) { setupVBO(); } + + // fixed http://www.cocos2d-x.org/issues/3990 + // Updates texture coords. + updateTexCoords(); } else { _totalParticles = tp; } + _emissionRate = _totalParticles / _life; resetSystem(); } diff --git a/cocos/2d/CCParticleSystemQuad.h b/cocos/2d/CCParticleSystemQuad.h index 42c338b304..f9974281bb 100644 --- a/cocos/2d/CCParticleSystemQuad.h +++ b/cocos/2d/CCParticleSystemQuad.h @@ -136,6 +136,9 @@ protected: /** initializes the texture with a rectangle measured Points */ void initTexCoordsWithRect(const Rect& rect); + /** Updates texture coords */ + void updateTexCoords(); + // Overrides /** * @js NA diff --git a/tests/test-cpp/Classes/ParticleTest/ParticleTest.cpp b/tests/test-cpp/Classes/ParticleTest/ParticleTest.cpp index 4893e74bdb..bf1480b1a9 100644 --- a/tests/test-cpp/Classes/ParticleTest/ParticleTest.cpp +++ b/tests/test-cpp/Classes/ParticleTest/ParticleTest.cpp @@ -958,7 +958,7 @@ enum static int sceneIdx = -1; -#define MAX_LAYER 44 +#define MAX_LAYER 45 Layer* createParticleLayer(int nIndex) { @@ -1009,6 +1009,7 @@ Layer* createParticleLayer(int nIndex) case 41: return new ReorderParticleSystems(); case 42: return new PremultipliedAlphaTest(); case 43: return new PremultipliedAlphaTest2(); + case 44: return new Issue3990(); default: break; } @@ -1889,9 +1890,43 @@ std::string PremultipliedAlphaTest2::subtitle() const return "Arrows should be faded"; } + +// Issue3990 + +void Issue3990::onEnter() +{ + ParticleDemo::onEnter(); + + _color->setColor(Color3B::BLACK); + this->removeChild(_background, true); + _background = NULL; + + _emitter = ParticleSystemQuad::create("Particles/Spiral.plist"); + + _emitter->setPositionType(ParticleSystem::PositionType::GROUPED); + _emitter->setTotalParticles(1000); + + _emitter->setPosition(VisibleRect::center()); + + _emitter->retain(); + this->addChild(_emitter ,10); +} + +std::string Issue3990::title() const +{ + return "Issue3990, setTotalParticle should work"; +} + +std::string Issue3990::subtitle() const +{ + return "Show '998' or '999' at bottom right side"; +} + +// void ParticleTestScene::runThisTest() { addChild(nextParticleAction()); Director::getInstance()->replaceScene(this); } + diff --git a/tests/test-cpp/Classes/ParticleTest/ParticleTest.h b/tests/test-cpp/Classes/ParticleTest/ParticleTest.h index 2bf2f530a2..5bee04114a 100644 --- a/tests/test-cpp/Classes/ParticleTest/ParticleTest.h +++ b/tests/test-cpp/Classes/ParticleTest/ParticleTest.h @@ -193,7 +193,7 @@ public: class Issue870 : public ParticleDemo { public: - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; void updateQuads(float dt); @@ -205,7 +205,7 @@ private: class Issue1201 : public ParticleDemo { public: - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -213,7 +213,7 @@ public: class ParticleBatchHybrid : public ParticleDemo { public: - virtual void onEnter(); + virtual void onEnter() override; void switchRender(float dt); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -225,7 +225,7 @@ private: class ParticleBatchMultipleEmitters : public ParticleDemo { public: - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -233,7 +233,7 @@ public: class ParticleReorder : public ParticleDemo { public: - virtual void onEnter(); + virtual void onEnter() override; void reorderParticles(float dt); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -244,7 +244,7 @@ private: class MultipleParticleSystems : public ParticleDemo { public: - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; virtual void update(float dt); @@ -253,8 +253,8 @@ public: class MultipleParticleSystemsBatched : public ParticleDemo { public: - virtual void onEnter(); - virtual void update(float dt); + virtual void onEnter() override; + virtual void update(float dt) override; virtual std::string title() const override; virtual std::string subtitle() const override; private: @@ -264,8 +264,8 @@ private: class AddAndDeleteParticleSystems : public ParticleDemo { public: - virtual void onEnter(); - virtual void update(float dt); + virtual void onEnter() override; + virtual void update(float dt) override; void removeSystem(float dt); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -276,9 +276,9 @@ private: class ReorderParticleSystems : public ParticleDemo { public: - virtual void onEnter(); + virtual void onEnter() override; void reorderSystem(float time); - virtual void update(float dt); + virtual void update(float dt) override; virtual std::string title() const override; virtual std::string subtitle() const override; private: @@ -288,7 +288,7 @@ private: class PremultipliedAlphaTest : public ParticleDemo { public: - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -296,7 +296,15 @@ public: class PremultipliedAlphaTest2 : public ParticleDemo { public: - virtual void onEnter(); + virtual void onEnter() override; + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + +class Issue3990 : public ParticleDemo +{ +public: + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; };