aboutsummaryrefslogtreecommitdiff
path: root/examples/particle_system/main.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-26 08:37:17 +0800
committerchai <chaifix@163.com>2018-11-26 08:37:17 +0800
commit24b712a956a48f43788e1c11e121aedf52e22278 (patch)
tree0bbccc98f1cb24c44cfb58ca99ce305b9f513e09 /examples/particle_system/main.cpp
parent1d54138b94a384917d47abd8109c586b1b7ac323 (diff)
*粒子系统
Diffstat (limited to 'examples/particle_system/main.cpp')
-rw-r--r--examples/particle_system/main.cpp39
1 files changed, 26 insertions, 13 deletions
diff --git a/examples/particle_system/main.cpp b/examples/particle_system/main.cpp
index 1d47689..1c76ee6 100644
--- a/examples/particle_system/main.cpp
+++ b/examples/particle_system/main.cpp
@@ -39,8 +39,17 @@ const char* shader_code = R"(
#END_FRAGMENT_SHADER
)";
const float Pi = 3.14f;
+Texture* textures[10];
+Sprite* sprites[10];
void onLoad()
{
+ for (int i = 0; i < 10; ++i)
+ {
+ string name = string("dust/s_dust_A_") + std::to_string(i) + ".png";
+ textures[i] = Texture::createTexture(name.c_str());
+ sprites[i] = new Sprite(textures[i], Origin::MIDDLECENTER);
+ }
+
tex = Texture::createTexture("particle.png");
spr = new Sprite(tex, Origin::MIDDLECENTER);
tex1 = Texture::createTexture("texture.png");
@@ -95,25 +104,29 @@ void onLoad()
def.particleDef.scaleDef.overTime.value.addPoint(1, 0.7);
*/
p = new ParticleSystem();
- p->setEmitRate(0.01);
- p->setEmitForce(80, 150);
+ p->setEmitRate(0.02);
+ p->setEmitForce(80, 120);
//p->setEmitPosition(Vector2<float>(-2, -2), Vector2<float>(2, 2));
p->setEmitPosition(Vector2<float>());
- p->setEmitDirection(-Pi / 8 - Pi / 2, Pi / 8 - Pi / 2);
+ p->setEmitDirection(-Pi / 10 - Pi / 2, Pi / 10 - Pi / 2);
p->setParticleLinearAccelaration(Vector2<float>(0, 10));
- p->setParticleSpritesMode(SpriteMode::RANDOM);
- p->addParticleSprites(2, spr, spr1, spr2);
- p->addParticleColorPoint(Color(255, 100, 0, 255), 0);
- p->addParticleColorPoint(Color(255, 255, 0, 100), 0.3);
- p->addParticleColorPoint(Color(0, 255, 100, 255), 0.5);
- p->addParticleColorPoint(Color(255, 0, 0, 255), 1);
- //p->setParticleColor(Color(255, 30, 0, 255));
+ p->setParticleSpritesMode(SpriteMode::ANIMATED);
+ //p->addParticleSprites(2, spr, spr1, spr2);
+ for (int i = 0; i < 10; ++i)
+ p->addParticleSprite(sprites[i]);
+ //p->addParticleColorPoint(Color(255, 100, 0, 255), 0);
+ //p->addParticleColorPoint(Color(0, 255, 100, 255), 0.5);
+ //p->addParticleColorPoint(Color(255, 0, 0, 255), 1);
+ p->setParticleColor(Color(255, 30, 0, 255));
p->addParticleTransparencyPoint(1, 0);
- p->addParticleTransparencyPoint(0.7, 1);
+ p->addParticleTransparencyPoint(0, 0.5);
p->enableParticleBlendAdditive(true);
p->setParticleLife(0.5, 2);
- p->addParticleScalePoint(1, 0);
- p->addParticleScalePoint(0.7, 1);
+ p->addParticleScalePoint(3, 0);
+ p->addParticleScalePoint(0, 1);
+ timer.every(3, [=](void*)->void {
+ //p->setEmitForce()
+ });
}
void onEvent(Event* e)