void BirdMode::touchEnded(Touch *touch) { auto emitPtr = _touches.find(touch); ParticleSystemQuad *emit = nullptr; auto touchPos = this->convertToNodeSpace(touch->getLocation()); if (emitPtr != _touches.end()) { emit = emitPtr->second.emitter; touchPos.x = XtoAB(touchPos.x, getChordMaxX(), getNoteMaxX()); noteTouchEnded(getTouchLocation(touchPos), &emitPtr->second); } else if (firstTouch.first == touch) { emit = firstTouch.second.emitter; touchPos.x = XtoAB(touchPos.x, 0, getChordMaxX()); chordTouchEnded(getTouchLocation(touchPos), &firstTouch.second); firstTouch.first = 0; } else return; if (emit) { emit->setPosition(touchPos); emit->setDuration(0.2); emit->setSpeed(emit->getSpeed() * 2); emit->setAutoRemoveOnFinish(true); _touches.erase(touch); } }
void StarNode::UI_addParticle(){ Point delta = _starRef->getStartPoint() - _starRef->getEndPoint(); //出一个星星试试 ParticleSystemQuad *particle = CCParticleSystemQuad::create("Shoot.plist"); this->addChild( particle ); particle->setDuration( _starRef->getDuration() ); //持续时间 particle->setPosition( Point() ); //上270下90左0右180 float x = delta.x; float y = delta.y; float angle ; if ( ( delta.x > -0.01 || delta.x < 0.01 ) ) { angle = 270; }else{ angle = fabs( atanf( delta.y/delta.x ) *180/3.1415 ); } if ( x >= 0 && y > 0) { }else if ( x < 0 && y >= 0 ){ angle += 90; }else if ( x < 0 && y <= 0 ){ angle += 180; }else if ( x >= 0 && y < 0 ){ angle += 270; } particle->setAngle( angle ); particle->setAngleVar( 0 ); }
//碰撞检测 void StartGame::testCollin(float dt){ auto visibleSize=Director::getInstance()->getWinSize(); __Array *tempItemArray=__Array::create(); tempItemArray->retain(); Item *item; for (int i=0; i<itemArray->count(); i++) { item=(Item*)itemArray->getObjectAtIndex(i); if (Tools::isCollision(hook, item)&&!hook->hookAction&&!item->itemAction) { hook->stopAllActions(); miner->MinerAction(); tempItemArray->addObject(item); hook->hookAction = true; item->itemAction=true; if (toggle->getSelectedIndex()==1) { dt=0.5; }else{ dt=2.0; } auto move=MoveTo::create(dt, Vec2(visibleSize.width/2-5,visibleSize.height/2-20)); auto call=CallFunc::create(CC_CALLBACK_0(StartGame::move, this)); auto sequence=Sequence::create(move,call, NULL); hook->runAction(sequence); if (item->itemAction) { item->setRotation(hook->getRotation()); item->setAnchorPoint(Point(0.5, 1)); hook->setAnchorPoint(Point(0.5, 0.7)); item->setPosition(hook->getPosition()); hook->setAnchorPoint(Point(0.5, 1)); } if (item->_type==diamond||item->_type==secret) { ParticleSystemQuad* quad = ParticleSystemQuad::create("Boom.plist"); quad->setBlendAdditive(true); quad->setAutoRemoveOnFinish(true); quad->setPosition(item->getPosition()); quad->setDuration(0.2); this->addChild(quad); } auto move1=MoveTo::create(dt, Vec2(visibleSize.width/2-5,visibleSize.height/2-20)); auto call1=CallFuncN::create(CC_CALLBACK_1(StartGame::removeItem, this)); auto sequence1=Sequence::create(move1,call1, NULL); item->runAction(sequence1); } } itemArray->removeObjectsInArray(tempItemArray); tempItemArray->release(); }
void ChainReactionScene::update(float df) { for ( size_t i = 0; i < _ballClones.size(); ++i ) { _ballClones[i]->update(df); if ( _lastExplosion && Util::collides(_lastExplosion, _ballClones[i] ) ) { ++_chainedExplosionCount; ParticleSystemQuad* particleSystem = ParticleExplosion::create(); this->addChild(particleSystem, 10); particleSystem->setTexture( Director::getInstance()->getTextureCache()->addImage("Stars2.png") ); particleSystem->setAutoRemoveOnFinish(true); particleSystem->setPosition( _ballClones[i]->getPosition() ); particleSystem->setDuration(1.0f); // Update the score _currenPlayerScore->addPoints(_chainedExplosionCount); log("Removing child %zi", i + 1); removeChild(_ballClones[i]); _ballClones.erase( _ballClones.begin() + i ); } } }