本文整理汇总了C++中CCParticleSystem::setLife方法的典型用法代码示例。如果您正苦于以下问题:C++ CCParticleSystem::setLife方法的具体用法?C++ CCParticleSystem::setLife怎么用?C++ CCParticleSystem::setLife使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCParticleSystem
的用法示例。
在下文中一共展示了CCParticleSystem::setLife方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getChildByTag
void ParticlePerformTest4::doTest()
{
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCParticleSystem *particleSystem = (CCParticleSystem*) getChildByTag(kTagParticleSystem);
// duration
particleSystem->setDuration(-1);
// gravity
particleSystem->setGravity(ccp(0,-90));
// angle
particleSystem->setAngle(90);
particleSystem->setAngleVar(0);
// radial
particleSystem->setRadialAccel(0);
particleSystem->setRadialAccelVar(0);
// speed of particles
particleSystem->setSpeed(180);
particleSystem->setSpeedVar(50);
// emitter position
particleSystem->setPosition(ccp(s.width/2, 100));
particleSystem->setPosVar(ccp(s.width/2,0));
// life of particles
particleSystem->setLife(2.0f);
particleSystem->setLifeVar(1);
// emits per frame
particleSystem->setEmissionRate(particleSystem->getTotalParticles() / particleSystem->getLife());
// color of particles
ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f};
particleSystem->setStartColor(startColor);
ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f};
particleSystem->setStartColorVar(startColorVar);
ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f};
particleSystem->setEndColor(endColor);
ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f};
particleSystem->setEndColorVar(endColorVar);
// size, in pixels
particleSystem->setEndSize(64.0f);
particleSystem->setStartSize(64.0f);
particleSystem->setEndSizeVar(0);
particleSystem->setStartSizeVar(0);
// additive
particleSystem->setBlendAdditive(false);
}
示例2: CCPointMake
IntervalLayer::IntervalLayer()
{
m_time0 = m_time1 = m_time2 = m_time3 = m_time4 = 0.0f;
CCSize s = CCDirector::sharedDirector()->getWinSize();
// sun
CCParticleSystem* sun = CCParticleSun::node();
sun->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png"));
sun->setPosition( CCPointMake(s.width-32,s.height-32) );
sun->setTotalParticles(130);
sun->setLife(0.6f);
this->addChild(sun);
// timers
m_label0 = CCLabelBMFont::labelWithString("0", "fonts/bitmapFontTest4.fnt");
m_label1 = CCLabelBMFont::labelWithString("0", "fonts/bitmapFontTest4.fnt");
m_label2 = CCLabelBMFont::labelWithString("0", "fonts/bitmapFontTest4.fnt");
m_label3 = CCLabelBMFont::labelWithString("0", "fonts/bitmapFontTest4.fnt");
m_label4 = CCLabelBMFont::labelWithString("0", "fonts/bitmapFontTest4.fnt");
scheduleUpdate();
schedule(schedule_selector(IntervalLayer::step1));
schedule(schedule_selector(IntervalLayer::step2), 0);
schedule(schedule_selector(IntervalLayer::step3), 1.0f);
schedule(schedule_selector(IntervalLayer::step4), 2.0f);
m_label0->setPosition(CCPointMake(s.width*1/6, s.height/2));
m_label1->setPosition(CCPointMake(s.width*2/6, s.height/2));
m_label2->setPosition(CCPointMake(s.width*3/6, s.height/2));
m_label3->setPosition(CCPointMake(s.width*4/6, s.height/2));
m_label4->setPosition(CCPointMake(s.width*5/6, s.height/2));
addChild(m_label0);
addChild(m_label1);
addChild(m_label2);
addChild(m_label3);
addChild(m_label4);
// Sprite
CCSprite* sprite = CCSprite::spriteWithFile(s_pPathGrossini);
sprite->setPosition( CCPointMake(40,50) );
CCJumpBy* jump = CCJumpBy::actionWithDuration(3, CCPointMake(s.width-80,0), 50, 4);
addChild(sprite);
sprite->runAction( CCRepeatForever::actionWithAction(
(CCActionInterval*)(CCSequence::actions(jump, jump->reverse(), NULL ))
)
);
// pause button
CCMenuItem* item1 = CCMenuItemFont::itemFromString("Pause", this, menu_selector(IntervalLayer::onPause) );
CCMenu* menu = CCMenu::menuWithItems(item1, NULL);
menu->setPosition( CCPointMake(s.width/2, s.height-50) );
addChild( menu );
}
示例3: initRain
void TestParticle::initRain()
{
CCParticleSystem *emitter = CCParticleRain::create();
emitter->retain();
addChild(emitter, 10);
CCPoint p = emitter->getPosition();
emitter->setPosition( ccp( p.x, p.y-100) );
emitter->setLife(4);
emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png") );
emitter->setPosition(ccp(400,50));
emitter->release();
}
示例4: initSnow
void TestParticle::initSnow()
{
CCParticleSystem *emitter = CCParticleSnow::create();
emitter->retain();
addChild(emitter, 10);
CCPoint p = emitter->getPosition();
emitter->setPosition( ccp( p.x, p.y-110) );
emitter->setLife(3);
emitter->setLifeVar(1);
// gravity
emitter->setGravity(ccp(0,-10));
// speed of particles
emitter->setSpeed(130);
emitter->setSpeedVar(30);
ccColor4F startColor = emitter->getStartColor();
startColor.r = 0.9f;
startColor.g = 0.9f;
startColor.b = 0.9f;
emitter->setStartColor(startColor);
ccColor4F startColorVar = emitter->getStartColorVar();
startColorVar.b = 0.1f;
emitter->setStartColorVar(startColorVar);
emitter->setEmissionRate(emitter->getTotalParticles()/emitter->getLife());
emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("snow.png"));
emitter->setPosition(ccp(0,480));
emitter->release();
}
示例5: initRotFlower
void TestParticle::initRotFlower()
{
CCParticleSystem *emitter = new CCParticleSystemQuad();
emitter->initWithTotalParticles(300);
//emitter->autorelease();
addChild(emitter);
////emitter->release(); // win32 : Remove this line
emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("stars2.png"));
// duration
emitter->setDuration(-1);
// gravity
emitter->setGravity(CCPointZero);
// angle
emitter->setAngle(90);
emitter->setAngleVar(360);
emitter->setSpeed(160);
emitter->setSpeedVar(20);
// radial
emitter->setRadialAccel(-120);
emitter->setRadialAccelVar(0);
// tagential
emitter->setTangentialAccel(30);
emitter->setTangentialAccelVar(0);
// emitter position
emitter->setPosition( ccp(160,240) );
emitter->setPosVar(CCPointZero);
// life of particles
emitter->setLife(3);
emitter->setLifeVar(1);
// spin of particles
emitter->setStartSpin(0);
emitter->setStartSpinVar(0);
emitter->setEndSpin(0);
emitter->setEndSpinVar(2000);
ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f};
emitter->setStartColor(startColor);
ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f};
emitter->setStartColorVar(startColorVar);
ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f};
emitter->setEndColor(endColor);
ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f};
emitter->setEndColorVar(endColorVar);
// size, in pixels
emitter->setStartSize(30.0f);
emitter->setStartSizeVar(00.0f);
emitter->setEndSize(kParticleStartSizeEqualToEndSize);
// emits per second
emitter->setEmissionRate(emitter->getTotalParticles()/emitter->getLife());
// additive
emitter->setBlendAdditive(false);
emitter->setPosition(ccp(size.width/6*5,size.height-250));
emitter->release();
}
示例6: FollowPath
void StartScene::FollowPath(Node *sender)
{
DataModel *m = DataModel::getModel();
Creep* creep = (Creep *)sender;
WayPoint* curWaypoint = creep->getCurrentWaypoint();
WayPoint* waypoint = creep->getNextWaypoint();
if (waypoint!=nullptr) {
Point moveVector = waypoint->getPosition()-curWaypoint->getPosition();
float angle = ccpToAngle(moveVector);
float cocosAngle = CC_RADIANS_TO_DEGREES(angle);
// std::ostringstream text("angle = ");
// text<<std::to_string(cocosAngle)<<" curPoint("<<std::to_string(curWaypoint->getPosition().x)<<","<<std::to_string(curWaypoint->getPosition().y)<<") nextPoint("<<std::to_string(waypoint->getPosition().x)<<","<<std::to_string(waypoint->getPosition().y)<<")";
// log(text.str().c_str());
if (cocosAngle==0) {
if (creep->inverse) {
cocosAngle += 180;
creep->lifeBar->setPosition(creep->sprite->getPosition().x, creep->sprite->getPosition().y-60);
} else
creep->lifeBar->setPosition(creep->sprite->getPosition().x, creep->sprite->getPosition().y+60);
creep->emptyLifeBar->setPosition(creep->lifeBar->getPosition());
} else if(cocosAngle==180) {
if (creep->inverse) {
cocosAngle += 180;
creep->lifeBar->setPosition(creep->sprite->getPosition().x, creep->sprite->getPosition().y+60);
} else
creep->lifeBar->setPosition(creep->sprite->getPosition().x, creep->sprite->getPosition().y-60);
creep->emptyLifeBar->setPosition(creep->lifeBar->getPosition());
} else {
if (!creep->inverse)
cocosAngle += 180;
}
sender->setRotation(cocosAngle);
int moveDuration = creep->moveDuration;
auto actionMove = MoveTo::create(moveDuration, waypoint->getPosition());
auto actionMoveDone = CallFuncN::create(this, callfuncN_selector(StartScene::FollowPath));
creep->stopAllActions();
// creep->lifeBar->stopAllActions();
creep->runAction(Sequence::create(actionMove, actionMoveDone, NULL));
// creep->lifeBar->runAction(Sequence::create(lifeBarActionMove, NULL));
} else {
m->home->homeHP--;
life->setText(to_string(m->home->homeHP));
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("blast.wav");
m->targets.eraseObject(creep);
this->removeChild(creep);
CCParticleSystem* particleSystem = CCParticleExplosion::create();
particleSystem->setTexture(CCTextureCache::sharedTextureCache()->addImage("bullet2.png"));
particleSystem->setPosition(creep->getPosition());
particleSystem->setScale(0.15);
particleSystem->setLife(1);
this->addChild(particleSystem);
if (m->home->homeHP<=0) {
m->home->removeAllChildren();
m->home->sprite = Sprite::create("destroy.png");
m->home->sprite->setScale(0.7);
m->home->addChild(m->home->sprite,0);
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
auto losePic = Sprite::create("over.png");
losePic->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(losePic,3);
widget = dynamic_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("OverUi_1/LoseUi_1.json"));
widget->setPosition(Point(visibleSize.width/2 + origin.x -widget->getContentSize().width/2, visibleSize.height/2 + origin.y - widget->getContentSize().height/2));
this->addChild(widget,2);
auto restartButton = dynamic_cast<Button*>(widget->getChildByName("RestartBTN"));
auto mainMenuButton = dynamic_cast<Button*>(widget->getChildByName("MainMenuBTN"));
restartButton->addTouchEventListener(this, toucheventselector(StartScene::restartEvent));
mainMenuButton->addTouchEventListener(this, toucheventselector(StartScene::mainMenuEvent));
this->cleanup();
} else {
std::string home = to_string(m->home->homeHP) + ".png";
m->home->removeAllChildren();
m->home->sprite = Sprite::create(home);
m->home->sprite->setScale(0.7);
m->home->addChild(m->home->sprite,0);
}
}
}
示例7: update
void StartScene::update(float dt)
{
DataModel *m = DataModel::getModel();
Vector<Projectile*> projectilesToDelete;
for (int i = 0; i < m->projectiles.size(); i++)
{
Projectile* projectile = (Projectile*)(m->projectiles.at(i));
Rect projectileRect = Rect(projectile->getPositionX() - (projectile->getContentSize().width / 2),
projectile->getPositionY() - (projectile->getContentSize().height / 2),
projectile->getContentSize().width,
projectile->getContentSize().height);
for (int i = 0; i < m->targets.size(); i++)
{
Creep* target = (Creep*)(m->targets.at(i));
Rect targetRect = Rect(target->getPositionX() - (target->sprite->getContentSize().width / 2),
target->getPositionY() - (target->sprite->getContentSize().height / 2),
target->sprite->getContentSize().width,
target->sprite->getContentSize().height);
if (projectileRect.intersectsRect(targetRect))
{
projectilesToDelete.pushBack(projectile);
Creep *creep = target;
creep->curHp -= projectile->power;
creep->lifeBar->setPercentage(static_cast<float>(creep->curHp*100)/creep->maxHp);
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("hit.wav");
if (creep->curHp <= 0)
{
// targetsToDelete.pushBack(creep);
m->targets.eraseObject(creep);
CCParticleSystem* particleSystem = CCParticleExplosion::create();
particleSystem->setTexture(CCTextureCache::sharedTextureCache()->addImage("bullet2.png"));
particleSystem->setPosition(creep->getPosition());
particleSystem->setScale(0.15);
particleSystem->setLife(1);
this->addChild(particleSystem);
// creep->removeAllChildren();
// creep->sprite = Sprite::create("blast7.png");
// creep->addChild(creep->sprite,0);
this->removeChild(creep,true);
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("blast.wav");
m->currentMoney += creep->bonusMoney;
money->setText(to_string(m->currentMoney));
}
// for (int i = 0; i < targetsToDelete.size(); i++)
// {
// Creep *target = (Creep*)(targetsToDelete.at(i));
// m->targets.eraseObject(target);
// this->removeChild(target, true);
// CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("blast.wav");
// }
break;
}
}
}
for (int i =0; i < projectilesToDelete.size(); i++)
{
Projectile *projectile = (Projectile*)(projectilesToDelete.at(i));
m->projectiles.eraseObject(projectile);
this->removeChild(projectile,true);
}
if (this->currentLevel==-1&&m->targets.size()==0) {
//win
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
// auto winPic = Sprite::create("win.png");
// winPic->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
//// winPic->setScale(2);
// this->addChild(winPic,2);
widget = dynamic_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("OverUi_1/WinUi_1.json"));
widget->setPosition(Point(visibleSize.width/2 + origin.x -widget->getContentSize().width/2, visibleSize.height/2 + origin.y - widget->getContentSize().height/2));
this->addChild(widget,2);
auto star1 = dynamic_cast<ImageView*>(widget->getChildByName("Star_1"));
auto star2 = dynamic_cast<ImageView*>(widget->getChildByName("Star_2"));
auto star3 = dynamic_cast<ImageView*>(widget->getChildByName("Star_3"));
auto restartButton = dynamic_cast<Button*>(widget->getChildByName("RestartBTN"));
auto continueButton = dynamic_cast<Button*>(widget->getChildByName("ContinueBTN"));
restartButton->addTouchEventListener(this, toucheventselector(StartScene::restartEvent));
continueButton->addTouchEventListener(this, toucheventselector(StartScene::continueEvent));
if (m->home->homeHP>=1&& m->home->homeHP<=3) {
star2->setVisible(false);
star3->setVisible(false);
} else if (m->home->homeHP>=4&&m->home->homeHP<=9) {
star3->setVisible(false);
}
this->cleanup();
}
}