void PlayLayer::explodeSushi(SushiSprite *sushi) { //log("explodeSushi ture"); float time = 0.3; // 1. action for sushi sushi->runAction(Sequence::create( ScaleTo::create(time, 0.0), CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, sushi)), NULL)); // 2. action for circle auto circleSprite = Sprite::create("circle.png"); addChild(circleSprite, 10); circleSprite->setPosition(sushi->getPosition()); circleSprite->setScale(0);// start size circleSprite->runAction(Sequence::create(ScaleTo::create(time, 1.0), CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, circleSprite)), NULL)); // 3. particle effect auto particleStars = ParticleSystemQuad::create("stars.plist"); particleStars->setAutoRemoveOnFinish(true); particleStars->setBlendAdditive(false); particleStars->setPosition(sushi->getPosition()); particleStars->setScale(0.3); addChild(particleStars, 20); //消除加分 setScore(); }
bool SmallDevil::ToDamage(int dmg){ hp -= dmg; auto blood = ParticleSystemQuad::create("bloodParticle.plist"); blood->setPosition(this->GetHitPoint()); blood->setPositionType(ParticleSystem::PositionType::RELATIVE); blood->setAutoRemoveOnFinish(true); CreatureLayer::GetInstance()->addChild(blood, 6); if(hp <= 0){ auto effect = Sprite::createWithSpriteFrameName("sdExplosion00.png"); effect->setPosition(this->getPosition()); effect->setAnchorPoint(Point::ANCHOR_MIDDLE); effect->setScale(info.option/5.0f); CreatureLayer::GetInstance()->addChild(effect, 6); auto act1 = Animation::create(); act1->setDelayPerUnit(0.03f); for(int i=0; i<4; i++){ auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(StringUtils::format("sdExplosion%02d.png", i)); act1->addSpriteFrame(frame); } auto act2 = Animate::create(act1); auto act3 = Sequence::create(act2, RemoveSelf::create(), NULL); effect->runAction(act3); return false; } return true; }
void GameLayer::explodeMonster(Monster *monster) { float time = 0.3; // 1. action for Monter monster->runAction(Sequence::create( ScaleTo::create(time, 0.0), CallFuncN::create(CC_CALLBACK_1(GameLayer::actionEndCallback, this)), NULL)); // 2. action for circle auto circleSprite = Sprite::create("circle.png"); addChild(circleSprite, 10); circleSprite->setPosition(monster->getPosition()); circleSprite->setScale(0);// start size circleSprite->runAction(Sequence::create(ScaleTo::create(time, 1.0), CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, circleSprite)), NULL)); // 3. particle effect auto particleStars = ParticleSystemQuad::create("stars.plist"); particleStars->setAutoRemoveOnFinish(true); particleStars->setBlendAdditive(false); particleStars->setPosition(monster->getPosition()); particleStars->setScale(0.3); addChild(particleStars, 20); }
void ParticleManager::addEmitter(const std::string& filename, const Point& position, int order) { auto emitter = getEmitter(filename); emitter->setPosition(position); emitter->setAutoRemoveOnFinish(true); getParent()->addChild(emitter, order); }
void GameScene::checkMatch(Pix* pix) { if (_blockManager->isMatching(pix)) { ZUtils::playEffect(SOUND_MATCH); updateScore(); pix->runAction(Sequence::create(ScaleTo::create(0.5f, 1.5f), CallFuncN::create([this](Node* node){ auto p = (Pix*)node; p->setVisible(false); p->setPosition(10000, 10000); p->setScale(1.0f); }), NULL )); } else { ZUtils::playEffect(SOUND_FAIL); auto p = ParticleSystemQuad::create("explode.plist"); p->setPosition(pix->getPosition() + Vec2(0, 64)); p->setAutoRemoveOnFinish(true); this->addChild(p, kControl); pix->setPosition(10000, 10000); pix->setVisible(false); onLoose(); } }
void PlayStage::countAnimeBoom(Point position) { auto mask = ClippingNode::create(); mask->setStencil(LayerColor::create(Color4B(0, 0, 0, 255), _screenSize.width, 240.0f)); mask->setAlphaThreshold(255); mask->setInverted(false); auto count_boom_anime = ParticleSystemQuad::create("count_boom_ver2.plist"); count_boom_anime->setAutoRemoveOnFinish(true); count_boom_anime->setPosition(position); count_boom_anime->setLifeVar(0.2f); auto chainLabel = Label::createWithBMFont("ui_font.fnt", std::to_string(chains) + " Chains!!"); chainLabel->setScale(0); chainLabel->runAction(Sequence::create(EaseBackIn::create(ScaleTo::create(0.4f, 2.0f)), EaseBackOut::create(ScaleTo::create(0.18f, 1.0f)), DelayTime::create(0.4f), FadeOut::create(0.3f), CallFunc::create(CC_CALLBACK_0(Label::removeFromParentAndCleanup, chainLabel, true)), NULL)); chainLabel->setPosition(position); //anime_sprite->addChild(count_anime); mask->addChild(count_boom_anime); mask->addChild(chainLabel); ballSheetMask->addChild(mask, 500); }
void PlayLayer::explodeSushi(SushiSprite *sushi) { // Thời gian hiệu ứng 0,3 giây float time = 0.3; // Thực hiện 2 hành động tuần tự, Co Sushi về kích thước, 0, 0, sau đó tự remove khỏi Contener cha sushi->runAction(Sequence::create(ScaleTo::create(time, 0.0), CallFuncN::create(CC_CALLBACK_1(PlayLayer::actionEndCallback, this)),NULL)); // Action của Sprite tròn, mô phỏng vụ nổ auto circleSprite = Sprite::create("circle.png"); // Tạo mới sprite tròn addChild(circleSprite, 10); circleSprite->setPosition(sushi->getPosition()); // Vị trí = vị trí Sushi circleSprite->setScale(0); // Kích thước đầu =0 // Thực hiện hành động tuần tự sau, Tăng kích thước lên tỷ lệ 1.0 trong thời gian 0,3 giây, sau đó xóa khỏi Layer circleSprite->runAction(Sequence::create(ScaleTo::create(time, 1.0), CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, circleSprite)), NULL)); // 3. Tạo hiệu ứng particleStars, CHÚ Ý auto particleStars = ParticleSystemQuad::create("stars.plist"); // Tạo mới particleStars->setAutoRemoveOnFinish(true); // Tự động remove khi xong việc particleStars->setBlendAdditive(false); // Thiết lập sự pha trộn thêm vào = false particleStars->setPosition(sushi->getPosition()); // Đặt vị trí tại Sushi nổ particleStars->setScale(0.3); // Thiết lập tỉ lệ 0.3 addChild(particleStars, 20); // Thêm vào Layer Play }
void IntroScene::playIntro() { AudioEngine::getInstance()->play(); auto emitter = ParticleSnow::createWithTotalParticles(1000); emitter->setGravity(Point(0, -20)); emitter->setAutoRemoveOnFinish(true); addChild(emitter, 10); }
void PlayStage::boomAnime(Point position) { auto particleStars = ParticleSystemQuad::create("star_boom_ver18.plist"); particleStars->setAutoRemoveOnFinish(true); particleStars->setBlendAdditive(true); particleStars->setScale(0.5f+chains*.1f); particleStars->setLife(0.2f + chains*0.02f); particleStars->setSpeed(400.0f + chains*20.0f); particleStars->setPosition(position); ballSheet->addChild(particleStars, 300); }
bool MonsterDieEffect::init(Vec2 appearpoint,Vec2 disappearpoint,std::string effectfile1,std::string effectfile2) { if (!Sprite::init()) { return false; } auto particle0 = ParticleSystemQuad::create(effectfile1); particle0->setGravity(disappearpoint-appearpoint); this->setPosition(appearpoint); particle0->setAutoRemoveOnFinish(true); this->addChild(particle0); auto particle1 = ParticleSystemQuad::create(effectfile2); particle1->setGravity(disappearpoint-appearpoint); this->setPosition(appearpoint); particle1->setAutoRemoveOnFinish(true); this->addChild(particle1); //做完特效移除自己 this->scheduleOnce(schedule_selector(MonsterDieEffect::autoRemoveSelf),2); return true; }
void Animal::fight(AbstractBattleEntity* entity) { if (canAttack() == false) { return; } _state = AnimalState::Battle; _target = entity; _target->retain(); Vec2 originPoint = getPosition(); Vec2 targetPoint = ZMath::divideInternally(getPosition(), entity->getPosition(), 1, 2); auto size = _image->getContentSize() * getScale(); Vec2 effectPoint = ZMath::divideInternally(getPosition(), entity->getPosition(), 1, 1) + Vec2(0, size.height / 2); _timeline->play("default", false); _stopMoveAction(); _moveAction = runAction(RepeatForever::create(Sequence::create( MoveTo::create(0.1f, targetPoint), CallFunc::create([this, effectPoint]() { // sound effect if (isEnemy() || isOpponent()) { SoundManager::getInstance()->playFight2Sound(); } else { SoundManager::getInstance()->playFightSound(); } // particle effect auto effect = ParticleSystemQuad::create("effect/hit3.plist"); effect->setScale(getScale()); effect->setPosition(effectPoint); effect->setZOrder(100000); effect->setAutoRemoveOnFinish(true); auto parent = getParent(); if (parent) { parent->addChild(effect); } }), MoveTo::create(0.3f, originPoint), DelayTime::create(0.5f), NULL ))); _moveAction->retain(); if (startFightCallback) { startFightCallback(this, _target); } }
void PlayStage::countAnime(Point position) { //auto anime_sprite = Sprite::create(); auto mask = ClippingNode::create(); mask->setStencil(LayerColor::create(Color4B(0, 0, 0, 255), _screenSize.width, 240.0f)); mask->setAlphaThreshold(255); mask->setInverted(false); auto count_anime = ParticleSystemQuad::create("Count_anime.plist"); count_anime->setAutoRemoveOnFinish(true); count_anime->setPosition(position); //anime_sprite->addChild(count_anime); mask->addChild(count_anime); ballSheetMask->addChild(mask, 500); }
/* * 定期処理。 */ void ParticleAnime::process() { waitFrame--; if( waitFrame > 0 ) return; if( !isStart ) { setAutoRemoveOnFinish( true ); layerID->addChild( this, zOrder ); isStart = true; } //CCLog( "particle path=%s", path.c_str() ); }
void EvilQueenBlade::Arrive(bool isBullet){ auto particle = ParticleSystemQuad::create("shatterParticle.plist"); particle->setPosition(this->getPosition()); particle->setAutoRemoveOnFinish(true); particle->setPositionType(ParticleSystem::PositionType::RELATIVE); CreatureLayer::GetInstance()->addChild(particle, 6); this->runAction(TintTo::create(0.5f, 0, 0, 0)); if(aim) CreatureLayer::GetInstance()->removeChild(aim); if(isBullet) CreatureLayer::GetInstance()->EraseBullet(this); else CreatureLayer::GetInstance()->EraseMissile(this); this->unscheduleUpdate(); }
bool MainScene::init(){ if(!Layer::init()){ return false; } auto winSize = Director::getInstance()->getWinSize(); //TJA読み込み Tja tja = Tja(); tja.loadTja(); _noteTimes = tja.getNoteTimes(); auto background = Sprite::create("background.png"); background->setPosition(Vec2(winSize.width / 2.0, winSize.height / 2.0)); this->addChild(background); auto scoreLabel = Label::createWithSystemFont(StringUtils::toString(_score), "Marker Felt", FONT_SIZE); scoreLabel->enableShadow(Color4B::BLACK, Size(0.5, 0.5), 3); scoreLabel->enableOutline(Color4B::BLACK, 1.5); scoreLabel->setPosition(Vec2(winSize.width / 2 * 1.5, winSize.height - 40)); this->setScoreLabel(scoreLabel); this->addChild(scoreLabel); auto scoreLabelHeader = Label::createWithSystemFont("SCORE", "Marker Felt", FONT_SIZE); scoreLabelHeader->setPosition(Vec2(winSize.width / 2 * 1.5, winSize.height - 20)); this->addChild(scoreLabelHeader); int second = static_cast<int>(_second); auto secondLabel = Label::createWithSystemFont(StringUtils::toString(second), "Marker Felt", FONT_SIZE); secondLabel->setPosition(Vec2(winSize.width / 2, winSize.height - 40)); this->setSecondLabel(secondLabel); this->addChild(secondLabel); auto secondLabelHeader = Label::createWithSystemFont("TIME", "Marker Felt", FONT_SIZE); secondLabelHeader->setPosition(Vec2(winSize.width / 2, winSize.height - 20)); this->addChild(secondLabelHeader); //当たり判定 auto hitDetection = DrawNode::create(); hitDetection->drawDot(INIT_PLAYER_POSITION, 10.0f, Color4F(1.0f, 6.0f, 5.0f, 1.0f)); this->addChild(hitDetection); auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [this](Touch *touch, Event *event){ this->setTouchLocation(touch->getLocation()); return true; }; listener->onTouchMoved = [this](Touch *touch, Event *event){ SwipeDirection swipeDirection = this->getSwipeDirection(touch); if(swipeDirection != SwipeDirection::NONE){ // if(swipeDirection == SwipeDirection::RIGHT){ // if(_isSwipeTimeRight <= 0){ // this->initSwipeTime(); // this->setIsSwipeTimeRight(SWIPE_WAIT_TIME); // //音 // CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("dong.mp3"); // //エフェクト // auto explosion = ParticleFire::create(); // explosion->setPosition(INIT_PLAYER_POSITION); // explosion->setDuration(0.0001); // this->addChild(explosion); // explosion->setAutoRemoveOnFinish(true); // 表示が終わったら自分を親から削除! // } // } // else if(swipeDirection == SwipeDirection::LEFT){ // if(_isSwipeTimeLeft <= 0){ // this->initSwipeTime(); // this->setIsSwipeTimeLeft(SWIPE_WAIT_TIME); // //音 // CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("dong.mp3"); // //エフェクト // auto explosion = ParticleFire::create(); // explosion->setPosition(INIT_PLAYER_POSITION); // explosion->setDuration(0.0001); // explosion->setAutoRemoveOnFinish(true); // 表示が終わったら自分を親から削除! // this->addChild(explosion); // } // } if(swipeDirection == SwipeDirection::UP){ if(_isSwipeTimeUp <= 0){ this->initSwipeTime(); this->setIsSwipeTimeUp(SWIPE_WAIT_TIME); //音 CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("dong.mp3"); //エフェクト auto explosion = ParticleFire::create(); explosion->setPosition(INIT_PLAYER_POSITION); explosion->setDuration(0.0001); explosion->setAutoRemoveOnFinish(true); // 表示が終わったら自分を親から削除! this->addChild(explosion); } } else if(swipeDirection == SwipeDirection::DOWN){ if(_isSwipeTimeDown <= 0){ this->initSwipeTime(); this->setIsSwipeTimeDown(SWIPE_WAIT_TIME); //音 CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("dong.mp3"); //エフェクト auto explosion = ParticleFire::create(); explosion->setPosition(INIT_PLAYER_POSITION); explosion->setDuration(0.0001); explosion->setAutoRemoveOnFinish(true); // 表示が終わったら自分を親から削除! this->addChild(explosion); } } this->setTouchLocation(touch->getLocation()); } }; Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); //this->scheduleUpdate(); schedule(schedule_selector(MainScene::test), SFRAME_RATE); return true; }
void FloatingEffectManager::toast_cure(const cocos2d::Vec2& srcPos, const cocos2d::Vec2& desPos, DDElementType elementType, int level) { const float speed = 300; float len = (desPos-srcPos).length(); if (len == 0) { return; } auto _emitter = ParticleSystemQuad::createWithTotalParticles(500); _emitter->setAutoRemoveOnFinish(true); _layer->addChild(_emitter, 10); _emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("images/test_lizi.png")); _emitter->setDuration(len/speed); // gravity _emitter->setGravity(Vec2::ZERO); // angle _emitter->setAngle(vector2angel(desPos-srcPos)); _emitter->setAngleVar(0.5f* std::atan(DDConfig::battleCubeWidth()/len) * 180.f/3.1415926f); // speed of particles _emitter->setSpeed(speed); _emitter->setSpeedVar(0); // radial _emitter->setRadialAccel(-(speed/(2*len/speed))); _emitter->setRadialAccelVar(0); // tagential _emitter->setTangentialAccel(00); _emitter->setTangentialAccelVar(0); // emitter position // _emitter->setPosition( Vec2(160,240) ); _emitter->setPosVar({0,0}); // life of particles _emitter->setLife(2*len/speed); _emitter->setLifeVar(0); // spin of particles _emitter->setStartSpin(720); _emitter->setStartSizeVar(360); _emitter->setEndSpin(0); _emitter->setEndSpinVar(360); // color of particles Color4F startColor(0.f, 0.5f, 0.f, 0.8f); _emitter->setStartColor(startColor); Color4F startColorVar(0.f, 0.1f, 0.f, 0.1f); _emitter->setStartColorVar(startColorVar); Color4F endColor(0.1f, 0.5f, 0.1f, 0.8f); _emitter->setEndColor(endColor); Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.1f); _emitter->setEndColorVar(endColorVar); // size, in pixels _emitter->setStartSize(3.0f); _emitter->setStartSizeVar(1.0f); _emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE); // emits per second _emitter->setEmissionRate(_emitter->getTotalParticles()/_emitter->getLife()); // additive _emitter->setBlendAdditive(true); _emitter->setPosition(srcPos); }
void FloatingEffectManager::toast_help_tail(const cocos2d::Vec2& srcPos, const cocos2d::Vec2& desPos, const cocos2d::Color4F& color) { const float time = 0.2; float len = (desPos-srcPos).length(); if (len == 0) { return; } const float speed = len/time; auto _emitter = ParticleSystemQuad::createWithTotalParticles(500); _emitter->setAutoRemoveOnFinish(true); _layer->addChild(_emitter, 10); _emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("images/test_lizi.png")); _emitter->setDuration(time*5); // gravity _emitter->setGravity(Vec2::ZERO); // angle _emitter->setAngle(vector2angel(srcPos-desPos)); _emitter->setAngleVar(3); // speed of particles _emitter->setSpeed(speed/5); _emitter->setSpeedVar(0); // radial _emitter->setRadialAccel(0); _emitter->setRadialAccelVar(0); // tagential _emitter->setTangentialAccel(0); _emitter->setTangentialAccelVar(0); // emitter position // _emitter->setPosition( Vec2(160,240) ); _emitter->setPosVar({0,0}); // life of particles _emitter->setLife(0.2); _emitter->setLifeVar(0); // spin of particles _emitter->setStartSpin(720); _emitter->setStartSizeVar(360); _emitter->setEndSpin(0); _emitter->setEndSpinVar(360); // color of particles _emitter->setStartColor(color); Color4F startColorVar(0.f, 0.1f, 0.f, 0.1f); _emitter->setStartColorVar(startColorVar); _emitter->setEndColor(color); Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.1f); _emitter->setEndColorVar(endColorVar); // size, in pixels _emitter->setStartSize(2.0f); _emitter->setStartSizeVar(1.0f); _emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE); // emits per second _emitter->setEmissionRate(_emitter->getTotalParticles()/_emitter->getLife()); // additive _emitter->setBlendAdditive(true); _emitter->setPosition(srcPos); _emitter->runAction(MoveTo::create(0.1, desPos)); }
//检测碰撞,删除怪物 void GameLayer:: checkCollision(float f){ // log("检测碰撞"); Vector<Monster*>::iterator it;//哥布林 Vector<Bullet*>::iterator it1;//子弹 for (it1=bulletArray.begin(); it1!=bulletArray.end();it1++) { auto hh = *it1; //子弹 for (it=gebulinArray.begin(); it!=gebulinArray.end();it++ ) { auto gg = *it; //哥布林 if (iscollision(hh,gg)) { log("子弹和怪物碰撞"); //创建粒子 auto par = ParticleSun::create(); par->setDuration(0.5); par->setSpeed(100); par->setAutoRemoveOnFinish(true);//自动移除 par->setPosition(gg->getPosition()); addChild(par,1); gg->removeFromParent(); //列表中删除 gg=nullptr; score+=1; gebulinArray.erase(it); //数组中删除 log("怪物数==%zd",gebulinArray.size()); if (gebulinArray.size() ==0) { //怪物数0 显示胜利页面 //胜利页面 auto winLayer = WinLayer::createLayer(); winLayer->setPosition(Vec2::ZERO); winLayer->setWinDelegate(this); addChild(winLayer); //触摸吞噬 auto lis = EventListenerTouchOneByOne::create(); lis->setSwallowTouches(true); lis->onTouchBegan=([](Touch*, Event*){ return true; }); _eventDispatcher->addEventListenerWithSceneGraphPriority(lis, winLayer); } break; } } } //这种方法删除也是可以的 // for (int i = 0; i<gebulinArray.size(); i++) { // for (int j =0; j<bulletArray.size(); j++) { // // // if (iscollision(gebulinArray.at(i),bulletArray.at(j))) // { // gebulinArray.at(i)->removeFromParent() ; // gebulinArray.erase(i); // log("size = %zd",gebulinArray.size()); // } // } // // } }