本文整理汇总了C++中CCParticleSystem::setScale方法的典型用法代码示例。如果您正苦于以下问题:C++ CCParticleSystem::setScale方法的具体用法?C++ CCParticleSystem::setScale怎么用?C++ CCParticleSystem::setScale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCParticleSystem
的用法示例。
在下文中一共展示了CCParticleSystem::setScale方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
}
示例2: 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();
}
}