mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5328 from dumganhar/iss3990-particle
closed #3990: ParticleSystemQuad::setTotalParticles() can't set a value larger than the initialized value.
This commit is contained in:
commit
4ca47b3e5f
|
@ -200,6 +200,16 @@ void ParticleSystemQuad::initTexCoordsWithRect(const Rect& pointRect)
|
||||||
quads[i].tr.texCoords.v = top;
|
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)
|
void ParticleSystemQuad::setTextureWithRect(Texture2D *texture, const Rect& rect)
|
||||||
{
|
{
|
||||||
// Only update the texture if is different from the current one
|
// 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);
|
this->initTexCoordsWithRect(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleSystemQuad::setTexture(Texture2D* texture)
|
void ParticleSystemQuad::setTexture(Texture2D* texture)
|
||||||
{
|
{
|
||||||
const Size& s = texture->getContentSize();
|
const Size& s = texture->getContentSize();
|
||||||
this->setTextureWithRect(texture, Rect(0, 0, s.width, s.height));
|
this->setTextureWithRect(texture, Rect(0, 0, s.width, s.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleSystemQuad::setDisplayFrame(SpriteFrame *spriteFrame)
|
void ParticleSystemQuad::setDisplayFrame(SpriteFrame *spriteFrame)
|
||||||
{
|
{
|
||||||
CCASSERT(spriteFrame->getOffsetInPixels().equals(Point::ZERO),
|
CCASSERT(spriteFrame->getOffsetInPixels().equals(Point::ZERO),
|
||||||
|
@ -468,7 +480,6 @@ void ParticleSystemQuad::setTotalParticles(int tp)
|
||||||
_indices = indicesNew;
|
_indices = indicesNew;
|
||||||
|
|
||||||
// Clear the memory
|
// Clear the memory
|
||||||
// XXX: Bug? If the quads are cleared, then drawing doesn't work... WHY??? XXX
|
|
||||||
memset(_particles, 0, particlesSize);
|
memset(_particles, 0, particlesSize);
|
||||||
memset(_quads, 0, quadsSize);
|
memset(_quads, 0, quadsSize);
|
||||||
memset(_indices, 0, indicesSize);
|
memset(_indices, 0, indicesSize);
|
||||||
|
@ -506,12 +517,17 @@ void ParticleSystemQuad::setTotalParticles(int tp)
|
||||||
{
|
{
|
||||||
setupVBO();
|
setupVBO();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fixed http://www.cocos2d-x.org/issues/3990
|
||||||
|
// Updates texture coords.
|
||||||
|
updateTexCoords();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_totalParticles = tp;
|
_totalParticles = tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_emissionRate = _totalParticles / _life;
|
||||||
resetSystem();
|
resetSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,9 @@ protected:
|
||||||
/** initializes the texture with a rectangle measured Points */
|
/** initializes the texture with a rectangle measured Points */
|
||||||
void initTexCoordsWithRect(const Rect& rect);
|
void initTexCoordsWithRect(const Rect& rect);
|
||||||
|
|
||||||
|
/** Updates texture coords */
|
||||||
|
void updateTexCoords();
|
||||||
|
|
||||||
// Overrides
|
// Overrides
|
||||||
/**
|
/**
|
||||||
* @js NA
|
* @js NA
|
||||||
|
|
|
@ -958,7 +958,7 @@ enum
|
||||||
|
|
||||||
static int sceneIdx = -1;
|
static int sceneIdx = -1;
|
||||||
|
|
||||||
#define MAX_LAYER 44
|
#define MAX_LAYER 45
|
||||||
|
|
||||||
Layer* createParticleLayer(int nIndex)
|
Layer* createParticleLayer(int nIndex)
|
||||||
{
|
{
|
||||||
|
@ -1009,6 +1009,7 @@ Layer* createParticleLayer(int nIndex)
|
||||||
case 41: return new ReorderParticleSystems();
|
case 41: return new ReorderParticleSystems();
|
||||||
case 42: return new PremultipliedAlphaTest();
|
case 42: return new PremultipliedAlphaTest();
|
||||||
case 43: return new PremultipliedAlphaTest2();
|
case 43: return new PremultipliedAlphaTest2();
|
||||||
|
case 44: return new Issue3990();
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1889,9 +1890,43 @@ std::string PremultipliedAlphaTest2::subtitle() const
|
||||||
return "Arrows should be faded";
|
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()
|
void ParticleTestScene::runThisTest()
|
||||||
{
|
{
|
||||||
addChild(nextParticleAction());
|
addChild(nextParticleAction());
|
||||||
|
|
||||||
Director::getInstance()->replaceScene(this);
|
Director::getInstance()->replaceScene(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ public:
|
||||||
class Issue870 : public ParticleDemo
|
class Issue870 : public ParticleDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void onEnter();
|
virtual void onEnter() override;
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
void updateQuads(float dt);
|
void updateQuads(float dt);
|
||||||
|
@ -205,7 +205,7 @@ private:
|
||||||
class Issue1201 : public ParticleDemo
|
class Issue1201 : public ParticleDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void onEnter();
|
virtual void onEnter() override;
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
};
|
};
|
||||||
|
@ -213,7 +213,7 @@ public:
|
||||||
class ParticleBatchHybrid : public ParticleDemo
|
class ParticleBatchHybrid : public ParticleDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void onEnter();
|
virtual void onEnter() override;
|
||||||
void switchRender(float dt);
|
void switchRender(float dt);
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
|
@ -225,7 +225,7 @@ private:
|
||||||
class ParticleBatchMultipleEmitters : public ParticleDemo
|
class ParticleBatchMultipleEmitters : public ParticleDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void onEnter();
|
virtual void onEnter() override;
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
};
|
};
|
||||||
|
@ -233,7 +233,7 @@ public:
|
||||||
class ParticleReorder : public ParticleDemo
|
class ParticleReorder : public ParticleDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void onEnter();
|
virtual void onEnter() override;
|
||||||
void reorderParticles(float dt);
|
void reorderParticles(float dt);
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
|
@ -244,7 +244,7 @@ private:
|
||||||
class MultipleParticleSystems : public ParticleDemo
|
class MultipleParticleSystems : public ParticleDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void onEnter();
|
virtual void onEnter() override;
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
virtual void update(float dt);
|
virtual void update(float dt);
|
||||||
|
@ -253,8 +253,8 @@ public:
|
||||||
class MultipleParticleSystemsBatched : public ParticleDemo
|
class MultipleParticleSystemsBatched : public ParticleDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void onEnter();
|
virtual void onEnter() override;
|
||||||
virtual void update(float dt);
|
virtual void update(float dt) override;
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
private:
|
private:
|
||||||
|
@ -264,8 +264,8 @@ private:
|
||||||
class AddAndDeleteParticleSystems : public ParticleDemo
|
class AddAndDeleteParticleSystems : public ParticleDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void onEnter();
|
virtual void onEnter() override;
|
||||||
virtual void update(float dt);
|
virtual void update(float dt) override;
|
||||||
void removeSystem(float dt);
|
void removeSystem(float dt);
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
|
@ -276,9 +276,9 @@ private:
|
||||||
class ReorderParticleSystems : public ParticleDemo
|
class ReorderParticleSystems : public ParticleDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void onEnter();
|
virtual void onEnter() override;
|
||||||
void reorderSystem(float time);
|
void reorderSystem(float time);
|
||||||
virtual void update(float dt);
|
virtual void update(float dt) override;
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
private:
|
private:
|
||||||
|
@ -288,7 +288,7 @@ private:
|
||||||
class PremultipliedAlphaTest : public ParticleDemo
|
class PremultipliedAlphaTest : public ParticleDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void onEnter();
|
virtual void onEnter() override;
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
};
|
};
|
||||||
|
@ -296,7 +296,15 @@ public:
|
||||||
class PremultipliedAlphaTest2 : public ParticleDemo
|
class PremultipliedAlphaTest2 : public ParticleDemo
|
||||||
{
|
{
|
||||||
public:
|
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 title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue