diff options
author | chai <chaifix@163.com> | 2018-11-25 13:08:56 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-11-25 13:08:56 +0800 |
commit | 1d54138b94a384917d47abd8109c586b1b7ac323 (patch) | |
tree | 0ce0584b341c2619295ccf8cbcf6511e080c4fb5 /examples/particle_system/main.cpp | |
parent | 25b394738f08bc2e7b23f8343096f8296b46c633 (diff) |
*粒子系统
Diffstat (limited to 'examples/particle_system/main.cpp')
-rw-r--r-- | examples/particle_system/main.cpp | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/examples/particle_system/main.cpp b/examples/particle_system/main.cpp index 1d4bd7c..1d47689 100644 --- a/examples/particle_system/main.cpp +++ b/examples/particle_system/main.cpp @@ -42,12 +42,13 @@ const float Pi = 3.14f; void onLoad() { tex = Texture::createTexture("particle.png"); - spr = new Sprite(tex, Origin::MiddleCenter); + spr = new Sprite(tex, Origin::MIDDLECENTER); tex1 = Texture::createTexture("texture.png"); - spr1 = new Sprite(tex1, Origin::MiddleCenter); + spr1 = new Sprite(tex1, Origin::MIDDLECENTER); tex2 = Texture::createTexture("splash.png"); - spr2 = new Sprite(tex2, Origin::MiddleCenter); + spr2 = new Sprite(tex2, Origin::MIDDLECENTER); shader = Shader::createShader(shader_code); +/* ParticleSystemDef def; def.maxParticleCount = 30; @@ -58,8 +59,8 @@ void onLoad() def.emitterDef.forceDef.force.random.ceil = 150; def.emitterDef.positionDef.enableRandom = true; - def.emitterDef.positionDef.position.random.floor = Vector2<float>(-2, 0); - def.emitterDef.positionDef.position.random.ceil = Vector2<float>(2, 0); + def.emitterDef.positionDef.position.random.floor = Vector2<float>(-2, -2); + def.emitterDef.positionDef.position.random.ceil = Vector2<float>(2, 2); def.emitterDef.directionDef.enableRandom = true; def.emitterDef.directionDef.direction.random.floor = -Pi / 8 - Pi / 2 ; @@ -76,21 +77,43 @@ void onLoad() def.particleDef.colorDef.overTime.enable = true; def.particleDef.colorDef.overTime.value.addColor(Color(255, 100, 0, 255), 0); //def.particleDef.colorDef.overTime.value.addColor(Color(255, 255, 0, 100), 0.3); - //def.particleDef.colorDef.overTime.value.addColor(Color(0, 255, 100, 100), 0.5); - def.particleDef.colorDef.overTime.value.addColor(Color(255, 0, 0, 0), 1); + def.particleDef.colorDef.overTime.value.addColor(Color(0, 255, 100, 255), 0.5); + def.particleDef.colorDef.overTime.value.addColor(Color(255, 0, 0, 255), 1); + + def.particleDef.transparencyDef.overTime.enable = true; + def.particleDef.transparencyDef.overTime.value.addPoint(0, 1); + def.particleDef.transparencyDef.overTime.value.addPoint(0.6, 0); def.particleDef.blendDef.additive = true; def.particleDef.lifeTimeDef.enableRandom = true; def.particleDef.lifeTimeDef.life.random.floor = 0.5; - def.particleDef.lifeTimeDef.life.random.ceil = 1.5; + def.particleDef.lifeTimeDef.life.random.ceil = 2; def.particleDef.scaleDef.overTime.enable = true; def.particleDef.scaleDef.overTime.value.addPoint(0, 1); def.particleDef.scaleDef.overTime.value.addPoint(1, 0.7); - - p = new ParticleSystem(def); - //p->addSprite(spr); +*/ + p = new ParticleSystem(); + p->setEmitRate(0.01); + p->setEmitForce(80, 150); + //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->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->addParticleTransparencyPoint(1, 0); + p->addParticleTransparencyPoint(0.7, 1); + p->enableParticleBlendAdditive(true); + p->setParticleLife(0.5, 2); + p->addParticleScalePoint(1, 0); + p->addParticleScalePoint(0.7, 1); } void onEvent(Event* e) @@ -119,13 +142,13 @@ void onDraw() int main(int argc, char* argv[]) { - Application* Application = Application::get(); + Application* app = Application::get(); Application::Setting setting; setting.loader = onLoad; setting.eventHandler = onEvent; setting.updater = onUpdate; setting.drawer = onDraw; - Application->init(&setting); + app->init(&setting); AssetDatabase::get()->mount("."); @@ -142,9 +165,9 @@ int main(int argc, char* argv[]) wnd->init(&wndSetting); wnd->show(); - Application->run(); + app->run(); - Application->quit(); + app->quit(); wnd->quit(); return 0; |