一、创建带纹理的粒子效果(此处以下雨ParticleRain为例),并且可以加载自定义的纹理图案。
this->rain = ParticleRain::create(); this->rain->setTexture(Director::getInstance()->getTextureCache()->addImage("rain.png")); this->rain->setAutoRemoveOnFinish(true); this->rain->setZOrder(particle_rain_zorder); this->rain->setSpeed(600); this->rain->setScale(4); this->rain->setOpacity(100); this->rain->setTotalParticles(1000); this->addChild(this->rain);
二、使用粒子编辑器,并加载到游戏中
一个在线粒子效果编辑器:Particle2dx网址是:http://www.effecthub.com/particle2dx
制作完成后,将生成一个plist文件和一个png的纹理图片。
使用ParticleBatchNode可以增加效率。
ParticleSystem* mainpageParticle = ParticleSystemQuad::create("starterpage_particle.plist"); mainpageParticle->setPosVar(Vec2(screenSize.width, screenSize.height)); mainpageParticle->setPosition(0, 0); mainpageParticle->setAnchorPoint(Vec2(0, 0)); mainpageParticle->retain(); mainpageParticle->setPositionType(ParticleSystem::PositionType::RELATIVE); //设置位置类型 ParticleBatchNode* batch = ParticleBatchNode::createWithTexture(mainpageParticle->getTexture()); batch->addChild(mainpageParticle); this->particleSprite->addChild(batch); mainpageParticle->release();
时间: 2024-11-10 07:12:14