//------------------------------------------------------------------ // // ActionCallFunc // //------------------------------------------------------------------ void ActionCallFunc::onEnter() { ActionsDemo::onEnter(); centerSprites(3); CCFiniteTimeAction* action = CCSequence::actions( CCMoveBy::actionWithDuration(2, CGPointMake(200,0)), CCCallFunc::actionWithTarget(this, callfunc_selector(ActionCallFunc::callback1)), NULL); CCFiniteTimeAction* action2 = CCSequence::actions( CCScaleBy::actionWithDuration(2 , 2), CCFadeOut::actionWithDuration(2), CCCallFuncN::actionWithTarget(this, callfuncN_selector(ActionSequence2::callback2)), NULL); CCFiniteTimeAction* action3 = CCSequence::actions( CCRotateBy::actionWithDuration(3 , 360), CCFadeOut::actionWithDuration(2), CCCallFuncND::actionWithTarget(this, callfuncND_selector(ActionSequence2::callback3), (void*)0xbebabeba), NULL); m_grossini->runAction(action); m_tamara->runAction(action2); m_kathia->runAction(action3); }
void ActorLayer::TeleportActor(flownet::ActorID actorID, flownet::POINT currentPosition, flownet::POINT destinationPosition) { Actor* actor = GameClient::Instance().GetClientStage()->FindActor(actorID); ASSERT_DEBUG(actor); ActorNode* movingObject = this->FindActorNode(actorID); ASSERT_DEBUG(movingObject); if( !actor->IsAlive() ) { CCLOG("ActorLayer::MoveActor >> ignore actor move request. actor is dead"); return; } this->UpdateActorLookingDirection(actor, movingObject->getPosition(), PointConverter::Convert(destinationPosition)); movingObject->StopAnimationActions(); // NOTE : 자신한테 텔레포트 이펙트를 붙인채 싱크에 맞춰 이동할 수 있도록 한다 // NOTE : teleport effect node는 자동 소멸 할 수 있도록 플래그를 켠다 SpellEffectNode* effectNode = SpellEffectNode::create(actorID, SpellEffectType_Teleport); this->addChild(effectNode); CCFiniteTimeAction* animateMove = CCCallFunc::create(movingObject, callfunc_selector(ActorNode::AnimateMoving)); CCDelayTime* beforeDelay = CCDelayTime::create(0.1); CCFiniteTimeAction* actionMove = CCMoveTo::create(0, PointConverter::Convert(destinationPosition)); CCDelayTime* afterDelay = CCDelayTime::create(0.1); CCFiniteTimeAction* actionMoveDone = CCCallFunc::create( movingObject, callfunc_selector(ActorNode::AnimateIdle)); CCFiniteTimeAction* changeToIdleState = CCCallFuncN::create(this, callfuncN_selector(ActorLayer::ChangeActorStateToIdle)); CCAction* sequence = CCSequence::create(animateMove, beforeDelay, actionMove, afterDelay, actionMoveDone, changeToIdleState, NULL); // TO DO : show moving point sequence->setTag(ActionType_Animation); movingObject->runAction(sequence); }
void ActorLayer::ActorAttack(flownet::ActorID attackerActorID, flownet::ActorID targetActorID) { Actor* actor = GameClient::Instance().GetClientStage()->FindActor(attackerActorID); ActorNode* attackingObject = this->FindActorNode(attackerActorID); ActorNode* targetObject = this->FindActorNode(targetActorID); if(!actor) { return; } ASSERT_DEBUG(attackingObject); ASSERT_DEBUG(targetObject); if( !actor->IsAlive() ) { CCLOG("ActorLayer::ActorAttack >> ignore actor's attack request. actor is dead"); return; } ASSERT_DEBUG(actor->GetAttackSpeed() != 0); float attackDuration = 1 / actor->GetAttackSpeed(); attackingObject->StopAnimationActions(); this->UpdateActorLookingDirection(actor, attackingObject->getPosition(), targetObject->getPosition()); CCFiniteTimeAction* animateAttack = CCCallFunc::create(attackingObject, callfunc_selector(ActorNode::AnimateAttacking)); CCFiniteTimeAction* timeDuration = CCDelayTime::create(attackDuration); CCFiniteTimeAction* animateIdle = CCCallFunc::create(attackingObject, callfunc_selector(ActorNode::AnimateIdle)); CCFiniteTimeAction* changeToIdleState = CCCallFuncN::create(this, callfuncN_selector(ActorLayer::ChangeActorStateToIdle)); CCAction* sequence = CCSequence::create(animateAttack, timeDuration, animateIdle, changeToIdleState, NULL); sequence->setTag(ActionType_Animation); attackingObject->runAction(sequence); }
void EnemyLayer::addEnemy1(float dt) { //调用绑定敌机1 Enemy* enemy1 = Enemy::create(); enemy1->bindSprite(CCSprite::create("enermy1.png"), 100); //随机初始位置 CCSize enemy1Size = enemy1->getSprite()->getContentSize(); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); int minX = enemy1Size.width / 2; int maxX = winSize.width - enemy1Size.width / 2; int rangeX = maxX - minX; int actualX = (rand() % rangeX) + minX; enemy1->setPosition(ccp(actualX, winSize.height + enemy1Size.height / 2)); this->addChild(enemy1); this->m_pAllEnemy1->addObject(enemy1); //随机飞行速度 float minDuration, maxDuration; //根据游戏难度给minDuration,maxDuration赋值 int rangeDuration = maxDuration - minDuration; int actualDuration = (rand() % rangeDuration) + minDuration; CCFiniteTimeAction* actionMove = CCMoveTo::create(actualDuration, ccp(actualX, 0 - enemy1->getSprite()->getContentSize().height / 2)); CCFiniteTimeAction* actionDone = CCCallFuncN::create(this, callfuncN_selector(EnemyLayer::enemy1MoveFinished));//回调一个子弹结束处理函数 CCSequence* sequence = CCSequence::create(actionMove, actionDone); enemy1->runAction(sequence); }
void ActorLayer::MoveActor(flownet::ActorID actorID, flownet::POINT currentPosition, flownet::POINT destinationPosition) { Actor* actor = GameClient::Instance().GetClientStage()->FindActor(actorID); ASSERT_DEBUG(actor); ActorNode* movingObject = this->FindActorNode(actorID); ASSERT_DEBUG(movingObject); if( !actor->IsAlive() ) { CCLOG("ActorLayer::MoveActor >> ignore actor move request. actor is dead"); return; } float distance = destinationPosition.DistanceTo(currentPosition); // NOTE : using cocos2d object point because of distance is a bit diffence with server's ASSERT_DEBUG(actor->GetMovingSpeed() != 0); float duration = distance / actor->GetMovingSpeed(); this->UpdateActorLookingDirection(actor, movingObject->getPosition(), PointConverter::Convert(destinationPosition)); movingObject->StopAnimationActions(); CCFiniteTimeAction* animateMove = CCCallFunc::create(movingObject, callfunc_selector(ActorNode::AnimateMoving)); CCFiniteTimeAction* actionMove = CCMoveTo::create(duration, PointConverter::Convert(destinationPosition)); CCFiniteTimeAction* actionMoveDone = CCCallFunc::create( movingObject, callfunc_selector(ActorNode::AnimateIdle)); CCFiniteTimeAction* changeToIdleState = CCCallFuncN::create(this, callfuncN_selector(ActorLayer::ChangeActorStateToIdle)); CCAction* sequence = CCSequence::create(animateMove, actionMove, actionMoveDone, changeToIdleState, NULL); // TO DO : show moving point sequence->setTag(ActionType_Animation); movingObject->runAction(sequence); }
/** * add some enemies into game */ void HelloWorld::addTarget () { //CCRectMake size picture(27x40) CCSprite* target = CCSprite::create("Target.png", CCRectMake(0, 0, 27, 40)); //set tag target->setTag(1); mtargets->addObject(target); //get sizeWindown CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //get size target int minY = target->getContentSize().height/2; int maxY = winSize.height-target->getContentSize().height/2; int rangeY = maxY - minY; //random position target int actualY = (rand() % rangeY) + minY; target->setPosition(ccp( winSize.width+(target->getContentSize().width/2), actualY)); //add target into game this->addChild(target); //random speed from 2 to 4 int speed = (rand() % 2) + 2; //create the action move from position to min x with speed = speed CCFiniteTimeAction* actionMove = CCMoveTo::create((float)speed, ccp(0-target->getContentSize().width/2, actualY)); //action when target move finish: call function spriteMoveFinished CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create(this, callfuncN_selector(HelloWorld::spriteMoveFinished)); //action when target->runAction (CCSequence::create(actionMove, actionMoveDone, NULL)); }
void CQuickProduct::onUserStone(CCObject* pSender) { CButton *btn = (CButton*)pSender; CPopTip *tip = (CPopTip*)btn->getParent()->getParent(); CCScaleTo *smal = CCScaleTo::create(0.2f,0.0f); CCSequence *seque = CCSequence::createWithTwoActions(smal, CCCallFuncN::create(this,callfuncN_selector(CQuickProduct::removeTip))); tip->runAction(seque); if (btn->getTag()==1) { /*tip->removeFromParent();*/ // CPopTip *pop = CPopTip::create("tips/bg.png"); // pop->addBeforeImage("tips/blackbg.png",0,20); // pop->addButton("public/btn_yellow_befor.png","public/btn_yellow_after.png",nullptr,3,1); // pop->buttonAddImage("public/font_queiding.png",3); // pop->addTextRichTip("沒有足夠的鑽石",ccWHITE,"Arail",18.0f); // /*pop->addRichImage("mainCity/icon_11.png");*/ // pop->reloadTextRich(ccp(VCENTER.x,VCENTER.y+50)); // // pop->setBottomOffset(-10); // pop->setTouchEnabled(true); // pop->setTouchPriority(-100); // pop->setButtonLisener(this,ccw_click_selector(CQuickProduct::onUserStone)); // this->addChild(pop,10,2); // pop->runScaleAction(); // ShowPopTextTip(GETLANGSTR(263)); } LayerManager::instance()->pop(); LayerManager::instance()->pop(); }
bool ArrowTest::init() { if (!CCNode::init()) { return false; } CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); CCLayerColor* layer = CCLayerColor::create(ccc4(255, 255, 255, 255), screenSize.width, screenSize.height); addChild(layer); m_arrow = Arrow::create(); addChild(m_arrow); CCPoint startPoint = ccp(500,600); CCPoint endPoint = ccp(500,500); float shootHeight = 100; CCJumpTo* jump = CCJumpTo::create(0.5f, endPoint, shootHeight, 1); m_arrow->spawnAtPosition(startPoint); CCCallFuncN* callback = CCCallFuncN::create(m_arrow, callfuncN_selector(Arrow::shootEnd)); CCFiniteTimeAction* seq = CCSequence::create(jump, CCDelayTime::create(0.4f), callback, NULL); m_arrow->runAction(seq); return true; }
void EnemyLayer::addEnemy1(float dt){ Enemy* enemy1 = Enemy::create(); CCAnimation *animation; CCAnimate* animate; int enemyType = rand()%3; switch (enemyType) { case 0: enemy1->bindSprite(CCSprite::createWithSpriteFrame(enemy1SpriteFrame),Level1, ENEMY_MAX_LIFE1); break; case 1: enemy1->bindSprite(CCSprite::createWithSpriteFrame(enemy2SpriteFrame),Level2, ENEMY_MAX_LIFE2); break; case 2: enemy1->bindSprite(CCSprite::createWithSpriteFrame(enemy3SpriteFrame_1),Level3, ENEMY_MAX_LIFE3); animation = CCAnimation::create(); animation->setDelayPerUnit(0.2f); animation->addSpriteFrame(enemy3SpriteFrame_1); animation->addSpriteFrame(enemy3SpriteFrame_2); animate = CCAnimate::create(animation); enemy1->getSprite()->runAction(CCRepeatForever::create(animate)); break; default: enemy1->bindSprite(CCSprite::createWithSpriteFrame(enemy1SpriteFrame),Level1, ENEMY_MAX_LIFE1); break; } this->addChild(enemy1); m_pAllEnemy1->addObject(enemy1); CCSize enemy1Size = enemy1->getContentSize(); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); int minX = enemy1Size.width/2; int maxX =winSize.width -minX; int rangeX = maxX - minX; int aclX = (rand()%rangeX) + minX; enemy1->setPosition(ccp(aclX, winSize.height+enemy1Size.height)); float minDuration,maxDuration; switch (GameLayer::getGameLevel()) { case EASY: minDuration = 3; maxDuration = 8; break; case NORMAL: minDuration = 1; maxDuration = 3; break; case HARD: minDuration = 0.5; maxDuration = 1; break; default: break; } int rangeDuration = maxDuration - minDuration; int aclDuration = (rand()%rangeDuration) + minDuration; CCFiniteTimeAction* moveTo = CCMoveTo::create(aclDuration, ccp(aclX, -2*enemy1Size.height)); CCFiniteTimeAction* moveDone = CCCallFuncN::create(this, callfuncN_selector(EnemyLayer::enemyMoveFinish)); CCSequence* sequence = CCSequence::create(moveTo,moveDone); enemy1->runAction(sequence); }
void Unit_Bishop::Real_TouchMove(const CCPoint& movePos) { CCFiniteTimeAction* move = CCMoveTo::create(1.0f, movePos); CCFiniteTimeAction* callBack = CCCallFuncN::create(this, callfuncN_selector(Unit_Bishop::Delegate_FinishMove)); CCAction* action = CCSequence::create(move, callBack, NULL); sprite->runAction(action); }
void Towers::finishFiring() { if (!_target) { return; } DataModel *m = DataModel::getModel(); setNextBullet(Bullet::create(BULLET_NAME[bulletTag].c_str(),bulletTag,Info::getInfo()->bulletInfo->value[bulletTag])); getNextBullet()->setPosition(getPosition()); this->getParent()->addChild(getNextBullet(),1); m->getProjectiles()->addObject(getNextBullet()); float delta = 1.0; CCPoint shootVector = ccpSub(_target->getPosition(),getPosition()); CCPoint normalizedShootVector = ccpNormalize(shootVector); CCPoint overshotVector = ccpMult(normalizedShootVector, 320); CCPoint offscreenPoint = ccpAdd(getPosition(), overshotVector); getNextBullet()->runAction(CCSequence::create(CCMoveTo::create(delta,offscreenPoint), CCCallFuncN::create(this,callfuncN_selector( Towers::creepMoveFinished)),NULL)); getNextBullet()->setTag(bulletTag); setNextBullet(NULL); }
bool TextFieldTTFActionTest::onTextFieldDeleteBackward(CCTextFieldTTF * pSender, const char * delText, int nLen) { // create a delete text sprite and do some action CCLabelTTF * label = CCLabelTTF::create(delText, FONT_NAME, FONT_SIZE); this->addChild(label); // move the sprite to fly out CCPoint beginPos = pSender->getPosition(); CCSize textfieldSize = pSender->getContentSize(); CCSize labelSize = label->getContentSize(); beginPos.x += (textfieldSize.width - labelSize.width) / 2.0f; CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCPoint endPos(- winSize.width / 4.0f, winSize.height * (0.5 + (float)rand() / (2.0f * RAND_MAX))); float duration = 1; float rotateDuration = 0.2f; int repeatTime = 5; label->setPosition(beginPos); CCAction * seq = CCSequence::create( CCSpawn::create( CCMoveTo::create(duration, endPos), CCRepeat::create( CCRotateBy::create(rotateDuration, (rand()%2) ? 360 : -360), repeatTime), CCFadeOut::create(duration), 0), CCCallFuncN::create(this, callfuncN_selector(TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction)), 0); label->runAction(seq); return false; }
void ChatWidget::initInputBar() { float bw = 100; float bh = 70; if(1){ //send button m_sendButton = new BasButton; m_sendButton->setButtonInfo("",m_theme ,m_sendImg,CCSizeMake(bw,bh),m_sendPressedImg); this->addChild(m_sendButton); m_sendButton->setRight("parent",uilib::Right); m_sendButton->setBottom("parent",uilib::Bottom); m_sendButton->setMargins(2); m_sendButton->setClickCB(this,callfuncND_selector(ChatWidget::onSendButtonClicked)); } if(1){ //facing button m_facingButton = new BasButton; m_facingButton->setButtonInfo("",m_theme,"chatface",CCSizeMake(bh,bh)); this->addChild(m_facingButton); m_facingButton->setMargins(2); m_facingButton->setBottom("parent",uilib::Bottom); m_facingButton->setRight(m_sendButton->getName(),uilib::Left); m_facingButton->setClickCB(this,callfuncND_selector(ChatWidget::onFacingClicked)); } if(1){ //phrase button m_phraseButton = new BasButton; m_phraseButton->setButtonInfo("",m_theme,"chatuparrow",CCSizeMake(bh,bh)); this->addChild(m_phraseButton); m_phraseButton->setMargins(2); m_phraseButton->setBottom("parent",uilib::Bottom); m_phraseButton->setRight(m_facingButton->getName(),uilib::Left); m_phraseButton->setClickCB(this,callfuncND_selector(ChatWidget::onPhraseClicked)); } if(1){ //chat to button m_toButton = new BasButton; m_toButton->setButtonInfo("",m_theme,"chatto",CCSizeMake(bh,bh)); this->addChild(m_toButton); m_toButton->setMargins(2); m_toButton->setBottom("parent",uilib::Bottom); m_toButton->setLeft("parent",uilib::Left); m_toButton->setClickCB(this,callfuncND_selector(ChatWidget::onChatToClicked)); } if(1){ //init input m_inputBox = new InputBox; m_inputBox->setTheme(m_theme,"inputbg"); m_inputBox->setMaxLength(50); this->addChild(m_inputBox); m_inputBox->setMargins(2); m_inputBox->setMaxHeightRefSize(m_sendButton->getName(),1.0); m_inputBox->setMinHeightRefSize(m_sendButton->getName(),1.0); m_inputBox->setLeft(m_toButton->getName(),uilib::Right); m_inputBox->setBottom("parent",uilib::Bottom); m_inputBox->setRight(m_phraseButton->getName(),uilib::Left); m_inputBox->setOnReturned(this, callfuncN_selector(ChatWidget::onInputBoxReturned)); } }
void InGamePowers::OnPlayerClickTroll(Troll* theTroll) { mCurrentActiveTroll = theTroll; //What was the current power ?? if(mFreezeActive){ mFreezeActive = false; //Whats the cooldown for it? button_1->setEnabled(true); button_1->setOpacity(255); mGameScene->_mission_AP_Freezer+=1; mGameScene->CheckMissionByValue(MissionType_AP_Freezer,mGameScene->_mission_AP_Freezer); // Do some freeze FX - Like Master Dwarf fires his ball or stike CCSprite* aFlyBall = CCSprite::create("DebugDot.png"); int aSpawnX = mGameScene->_MasterDwarfBase->getPositionX(); int aSpawnY = mGameScene->_MasterDwarfBase->getPositionY()+mGameScene->_MasterDwarfBase->getContentSize().height; aFlyBall->setPosition(ccp(aSpawnX,aSpawnY)); // Where is that master troll powa stick? aFlyBall->setTag(FLY_BALL_MASTER_TROLL);// What is mGameScene->addChild(aFlyBall); // move it from master dwarf to the troll CCMoveTo* aMove1 = CCMoveTo::create(0.5f,ccp(theTroll->getPositionX(),theTroll->getPositionY())); CCCallFunc* aCall1 = CCCallFuncN::create(this, callfuncN_selector(InGamePowers::OnFreezeBallHit)); CCSequence* aSeq1 = CCSequence::create(aMove1,aCall1,NULL); // Stop the troll !!! Otherwise it runs away from our ball :D mCurrentActiveTroll->mFreezedTime = 5; // Maybe add some ??? above him !!! CCSprite* aWtfMsg = CCSprite::create("troll_warn.png"); aWtfMsg->setTag(TROLL_WTF_INDICATOR);// What is theTroll->addChild(aWtfMsg); //Run the action aFlyBall->runAction(aSeq1); } else if(mElectroActive){ mElectroActive = false; button_2->setEnabled(true); button_2->setOpacity(255); // Maybe add some ??? above him !!! CCSprite* aWtfMsg = CCSprite::create("troll_warn.png"); aWtfMsg->setTag(TROLL_WTF_INDICATOR);// What is theTroll->addChild(aWtfMsg); mGameScene->CreateBlitz(theTroll->getPositionX(),theTroll->getPositionY()-80,theTroll); } // Remove the indicator ? if(theTroll->getChildByTag(TROLL_SELECT_INDICATOR)!=NULL){ theTroll->removeChildByTag(TROLL_SELECT_INDICATOR); } }
void PopupLayer::setLotteryContext(Size size) { //Size winSize = Director::getInstance()->getWinSize(); Size center =(winSize - size)/2; //10*3的单元格 for(int row=0; row<10; row++) { for(int col=0; col<3; col++) { LotteryCard* card = LotteryCard::createCardSprite((row+1)+ col*10, 40,40, center.width+20+row*(size.width/11), (winSize.height/2+30)-40*col); card->setTag((row+1)+ col*10); card->setBallCallbackFunc(this,callfuncN_selector(PopupLayer::refreshBallBackGround)); addChild(card); lotteryVector.pushBack(card); for(int i=0;i<selected_number_vector.size();i++) { if(selected_number_vector.at(i) == (row+1)+ col*10) { card->setVisible(false); } } } } }
void MainScene::PushFlyingBubbles(const MatchesList_t& bubbles) { size_t size = bubbles.size(); for (size_t i = 0; i < size; ++i) { CCPointArray *array = CCPointArray::create(20); int x = m_BubbleViewDisplacement.x + bubbles[i].y * (BubbleElement::GetBubbleSize() + m_SpaceBetweenBubbles); int y = VisibleRect::top().y - m_BubbleViewDisplacement.y - BubbleElement::GetBubbleSize() - bubbles[i].x * (BubbleElement::GetBubbleSize() + m_SpaceBetweenBubbles); array->addControlPoint(ccp(x, y)); array->addControlPoint(ccp(x + 30, y + 30)); array->addControlPoint(ccp(x + 60, y + 50)); array->addControlPoint(ccp(x + 80, y + 70)); array->addControlPoint(ccp(750, 400)); CCCardinalSplineTo *action = CCCardinalSplineTo::create(1.5, array, 0); CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create( this, callfuncN_selector(MainScene::RemoveFlyingBubbles)); CCFiniteTimeAction *seq = CCSequence::create(action, actionMoveDone, NULL); BubbleElement* bubble = new BubbleElement(static_cast<BubbleElement*>(m_BubblesView[bubbles[i].y][bubbles[i].x])->GetType()); bubble->setPosition(CCPointMake(x, y)); bubble->runAction(seq); addChild(bubble); } }
void CCBlackHoleManager::runBlackHoleEffect(ccGridSize gridSize, ccTime duration, CCPoint bkPoint, CCNode *pTarget, const char *pszFileBlackHole) { if (this->m_isRunning) { return; } CCAssert(pTarget != NULL, "Invalid Target!"); CCNode *parent = (CCSprite *)pTarget->getParent(); CCAssert(parent != NULL, "Invalid parent!"); if (strcmp(pszFileBlackHole, "") != 0) { this->runBlackHoleSprite(parent, duration, bkPoint, pszFileBlackHole); } this->m_isRunning = true; pTarget->runAction(CCSequence::actions(CCSuckInAction::actionWithSize(gridSize, duration, bkPoint), CCCallFuncN::actionWithTarget(this, callfuncN_selector(CCBlackHoleManager::removeSprite)), NULL)); }
//移动背景图片 void SnowNight::moveBackgroundSprite(CCNode *sender) { int zorder = 0; if (sender != NULL) { zorder = sender->getZOrder(); sender->runAction(CCSequence::create(CCFadeOut::create(4),CCRemoveSelf::create(),NULL)); } //创建背景精灵 CCSprite *bgSprite = CCSprite::createWithTexture(bgTexture); float bgSpritespx = bgTexture->getContentSize().width; float bgSpritespy = bgTexture->getContentSize().height; //设置精灵位置 bgSprite->setPosition(ccp(0,winSize.height/2)); bgSprite->setScaleX(winSize.width/bgSpritespx*2);//宽度放大2倍 bgSprite->setScaleY(winSize.height/bgSpritespy); this->addChild(bgSprite, zorder-1); CCFiniteTimeAction* actionMove = CCMoveTo::create( (float)winSize.width/BACKGROUND_MOVE_SPEED,ccp(winSize.width, winSize.height/2) ); CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create( this,callfuncN_selector(SnowNight::moveBackgroundSprite)); bgSprite->runAction( CCSequence::create(actionMove,actionMoveDone, NULL) ); }
KDbool CScrGame::ccTouchBegan ( CCTouch* pTouch, CCEvent* pEvent ) { KDbool bRet = KD_FALSE; for ( KDuint i = 0; i < 2; i++ ) { CCRect tRect ( CCPointZero, m_uiPad[i][0]->getContentSize ( ) ); if ( tRect.containsPoint ( m_uiPad[i][0]->convertTouchToNodeSpace ( pTouch ) ) ) { bRet = KD_TRUE; m_uiPad[i][1]->setUserData ( pTouch ); m_uiPad[i][1]->setVisible ( KD_FALSE ); m_uiPad[i][2]->setVisible ( KD_TRUE ); if ( m_pWeapon->getAction ( i ) != CWeapon::eActHold || m_uBulletNum [ m_uWeaponIndex ][ i ] == 0 ) { continue; } CCFiniteTimeAction* pAction = ( CCSequence::create ( CCRepeat::create ( CCSequence::create ( CCCallFuncN::create ( this, callfuncN_selector ( CScrGame::onFire ) ), CCDelayTime::create ( m_pWeapon->getFireDelay ( ) / 1000.f ), KD_NULL ), KD_MIN ( m_pWeapon->getFireRepeat ( ), m_uBulletNum [ m_uWeaponIndex ][ i ] ) ), CCCallFuncN::create ( this, callfuncN_selector ( CScrGame::onFired ) ), KD_NULL ) ); m_uiPad[i][1]->runAction ( pAction ); } } if ( !bRet && m_tWorldTouch.getID ( ) == 0 ) { m_tWorldTouch = *pTouch; } return KD_TRUE; }
void HelloWorld::addTarget() { CCSprite *target = CCSprite::create("Target.png"); CCSize size = target->getContentSize(); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //위에서 아래로 떨어진다 int minX = target->getContentSize().width; int maxX = target->getContentSize().width*40; int rangeX = maxX - minX; int actualX = ( rand() % rangeX ) + minX; target->setPosition(ccp(actualX,winSize.height)); this->addChild(target); int minDuration = (int)2.0; int maxDuration = (int)4.0; int rangeDuration = maxDuration - minDuration; int actualDuration = ( rand() % rangeDuration ) + minDuration; CCFiniteTimeAction* actionMove = CCMoveTo::create((float)actualDuration, ccp(actualX,-1)); CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create(this,callfuncN_selector(HelloWorld::spriteMoveFinished)); target->runAction(CCSequence::create(actionMove, actionMoveDone, NULL)); /* //오른쪽에서 왼쪽으로 지나간다 int minY = target->getContentSize().height/2; int maxY = winSize.height - target->getContentSize().height/2; int rangeY = maxY - minY; int actualY = ( rand() % rangeY ) + minY; target->setPosition(ccp(winSize.width + (target->getContentSize().width/2),actualY)); this->addChild(target); int minDuration = (int)2.0; int maxDuration = (int)4.0; int rangeDuration = maxDuration - minDuration; int actualDuration = ( rand() % rangeDuration ) + minDuration; CCFiniteTimeAction* actionMove = CCMoveTo::create((float)actualDuration, ccp(0-target->getContentSize().width/2,actualY)); CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create(this,callfuncN_selector(HelloWorld::spriteMoveFinished)); target->runAction(CCSequence::create(actionMove, actionMoveDone, NULL)); */ target->setTag(1); _targets->addObject(target); }
void CardMgr::RunBeginAction() { //这个要设置为false,否则会宕机,原因未知。。。 SetTouchable(false); play_scene_->ShowStartTips(true); CCOrbitCamera * orbit1 = CCOrbitCamera::create(0.25, 0.5, 0, 0, 90, 0, 0); CCCallFuncN* change_card1 = CCCallFuncN::create(this, callfuncN_selector(CardMgr::ChangeCardToSpriteBack)); CCOrbitCamera * orbit2 = CCOrbitCamera::create(0.25, 0, -0.5, 90, 90, 0, 0); CCMoveBy* move1 = CCMoveBy::create(0.25, ccp(0,50)); CCMoveBy* move2 = CCMoveBy::create(0.25, ccp(0,-50)); CCOrbitCamera * orbit3 = CCOrbitCamera::create(0.25, 0.5, 0, 0, 90, 0, 0); CCCallFuncN* change_card2 = CCCallFuncN::create(this, callfuncN_selector(CardMgr::ChangeCardToSpriteFront)); CCOrbitCamera * orbit4 = CCOrbitCamera::create(0.25, 0, -0.5, 90, 90, 0, 0); CCCallFuncN* end = CCCallFuncN::create(this, callfuncN_selector(CardMgr::BeginActionEnd)); CCSequence* tmp = CCSequence::create(orbit1,change_card1,orbit2,move1,move2,orbit3,change_card2,orbit4,end,NULL); CCSprite* src = (CCSprite*)card_layer_->getChildByTag(bingo_index_); src->runAction(tmp); }
void RatingSprite::runAnimation(){ this->stopAllActions(); CCActionInterval* cd= CCScaleTo::create(2,1,1); CCActionInterval* cd2=CCScaleTo::create(2,1,0); CCCallFuncN *onComplete = CCCallFuncN::create(this, callfuncN_selector(RatingSprite::runAnimationCallBack)); CCSequence* ce=CCSequence::create(cd,cd2,onComplete,NULL); this->runAction(ce); }
void FairyControlPanel::setVisiable(){ if(!isDoClick){ CCActionInterval * moveBy = CCMoveBy::create(0.3f,ccp(0, -panelBack->getContentSize().height - 30)); panelBack->runAction(CCSequence::create(moveBy->reverse(), CCCallFuncN::create(this,callfuncN_selector(FairyControlPanel::finishDoClick)),NULL)); } }
void Zombie::z_move(){ float speed = this->z_speed; CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create(this->z_sprite_sheet,callfuncN_selector(Zombie::spriteMoveFinished)); float x = this->z_sprite_sheet->getPositionX(); float y = this->z_sprite_sheet->getPositionY(); if(this->z_alive()){ if((x == 128.0) && (y < 240.0)){ y = y + speed; this->z_sprite_sheet->setPosition(x,y); this->z_sprite_sheet->setVisible(true); } else if((x < 384.0) && (y >= 240.0)){ x = x + speed; this->z_sprite_sheet->setPosition(x,y); this->z_sprite_sheet->setVisible(true); } else if((x >= 384.0) && (y > 100.0)){ y = y - speed; this->z_sprite_sheet->setPosition(x,y); this->z_sprite_sheet->setVisible(true); } else if((x > 258.0) && (y <= 100.0)){ x = x - speed; this->z_sprite_sheet->setPosition(x,y); this->z_sprite_sheet->setVisible(true); } else if((x <= 258.0) && (y < 128.0)){ y = y + speed; this->z_sprite_sheet->setPosition(x,y); this->z_sprite_sheet->setVisible(true); } else if((x == 258.0) && (y == 128.0)) this->z_sprite_sheet->runAction(actionMoveDone); if((x == 128.0) && (y == 240.0)){ //printf(" zOrder = %d",this->z_sprite_sheet->getZOrder()); this->z_speed = 0.5; setSpriteBatch(5); } else if((x == 384.0) && (y ==240.0)){ this->z_sprite_sheet->setZOrder(60 - this->z_sprite_sheet->getZOrder()); setSpriteBatch(9); } else if((x == 384.0) && (y == 100.0)){ setSpriteBatch(13); } else if((x == 258.0) && (y == 100.0)){ this->z_sprite_sheet->setZOrder(60 - this->z_sprite_sheet->getZOrder()); setSpriteBatch(1); } } }
void CardMgr::MoveWithLine(CCSprite* src, CCPoint end_point, float time) { CCMoveTo* cur_action = CCMoveTo::create(time, end_point); CCCallFuncN* end = CCCallFuncN::create(this, callfuncN_selector(CardMgr::MoveEnd)); CCSequence* tmp = CCSequence::createWithTwoActions(cur_action, end); CCSequence* res = CCSequence::createWithTwoActions(CCDelayTime::create(0.3f), tmp); //移动的card的动画次数++ moved_card_nums_++; src->runAction(res); }
void CEnemySprite::setRun(float dt) { CCPointArray *pArray = CMoveTrackArray::getEnemyArray(m_iMoveType); CCCardinalSplineBy *pAction = CCCardinalSplineBy::create(10, pArray, 0); CCCallFuncN *pFunc = CCCallFuncN::create(this, callfuncN_selector(CEnemySprite::setDelFunc)); CCFiniteTimeAction *pMove = CCSequence::create(pAction, pFunc, NULL); m_pSprite->runAction(pMove); }
void BottleTower::fire(float dt){ if(isFinded){ CCString* animateName = CCString::createWithFormat((towerType+"%d").c_str(),towerLevel); CCAnimation* fireAnimation = animateCache->animationByName(animateName->getCString()); CCAnimate* fireAnimate = CCAnimate::create(fireAnimation); CCCallFuncN* cfn = CCCallFuncN::create(this,callfuncN_selector(BottleTower::creatBullte)); runAction(CCSequence::create(fireAnimate,cfn,NULL)); } }
void UIScrollLayer::goToPage(bool animated) { //CCSize pageSize = this->getContentSize(); CCSize contentSize = getContentSize(); if(animated) { if (m_ScrollDir == ESD_Horizontal) { CCMoveTo *moveTo = CCMoveTo::create(0.2f, CCPointMake(-m_CurPage * contentSize.width + m_ptCenter.x, m_ptCenter.y)); //m_baseLayer->runAction(moveTo); m_baseLayer->runAction(CCSequence::create(moveTo,CCCallFuncN::create(this,callfuncN_selector(UIScrollLayer::onMoveEnd)),NULL)); } else { CCMoveTo *moveTo = CCMoveTo::create(0.2f, CCPointMake(m_ptCenter.x , m_CurPage * contentSize.height + m_ptCenter.y)); //m_baseLayer->runAction(moveTo); m_baseLayer->runAction(CCSequence::create(moveTo,CCCallFuncN::create(this,callfuncN_selector(UIScrollLayer::onMoveEnd)),NULL)); } } else { if (m_ScrollDir == ESD_Horizontal) { m_baseLayer->setPosition(CCPointMake(-m_CurPage * contentSize.width + m_ptCenter.x, m_ptCenter.y)); } else { m_baseLayer->setPosition(CCPointMake(m_ptCenter.x, m_CurPage * contentSize.height + m_ptCenter.y)); } } checkChildrenPos(); clearIndicators(); addIndicators(m_ScrollDir); if(m_showPage != m_CurPage) { if(m_pageChangeTarget != NULL && m_pageChangeHandler != NULL) { (m_pageChangeTarget->*m_pageChangeHandler)(); } m_showPage = m_CurPage; } }
void Battle::playActionOver(cocostudio::Armature *armature, cocostudio::MovementEventType type, const char *name) { if (armature == m_pReadygo) { if (type == COMPLETE) { removeChild(armature); m_pReadygo = NULL; unmask(); BIND(BUND_ID_GLOBAL_TOUCH_MOVED, this, Battle::globalTouchMoved); g_pEventEngine->BundlerCall(BUND_ID_PLANE_FIRE, this, sizeof(this)); } } if (armature == m_pBossIn) { if (type == COMPLETE) { removeChild(armature); m_pBossIn = NULL; unmask(); const BossConfig * pconfig = g_pGameConfig->getBossConfig(m_pConfig->boss); m_pBoss = Boss::create(pconfig); addChild(m_pBoss, GRADE_ENEMY); if (m_pConfig->boss != "chisezhilang") { m_pBoss->setScale(g_pGameConfig->scaleEleMin); } else { m_pBoss->setScale(g_pGameConfig->scaleEleMin * 1.5); } m_pBoss->setPosition(Vec2(pconfig->pos.x * g_pGameConfig->scaleEleX, pconfig->pos.y * g_pGameConfig->scaleEleY)); m_pBoss->setRotation(pconfig->rotate); ActionInterval * action = MoveBy::create(2, Vec2(0, -500 * g_pGameConfig->scaleEleY)); m_pBoss->runAction(Sequence::create(action, CallFuncN::create(this, callfuncN_selector(Battle::playbossAi)), NULL)); } } if (armature == m_pMissionVictory) { if (type == COMPLETE) { Node * icon = g_pGameConfig->getIcon(m_equip.model, m_equip.type); icon->setPosition(Vec2(-200, -275)); icon->setScale(g_pGameConfig->scaleEleMin * 5); m_pMissionVictory->addChild(icon, GRADE_UI); icon->setOpacity(0); ActionInterval * scale = ScaleTo::create(.5f, g_pGameConfig->scaleEleMin * 1.5); ActionInterval * fadein = FadeIn::create(.5f); icon->runAction(Spawn::create(scale, fadein, NULL)); UNBIND(BUND_ID_GLOBAL_TOUCH_MOVED, this, Battle::globalTouchMoved); scheduleOnce(schedule_selector(Battle::returnMission), 2.0f); } } if (armature == m_pMissionFaild) { if (type == COMPLETE) { UNBIND(BUND_ID_GLOBAL_TOUCH_MOVED, this, Battle::globalTouchMoved); scheduleOnce(schedule_selector(Battle::returnMission), 2.0f); } } }
//花瓣飘落动作 void SGAnnouncementLayer::playFlowerAnim(CCSprite *spriteFlower) { int iTag = spriteFlower->getTag(); srand((unsigned)time(NULL)); float times, roTime; float fAngle1, fAngle2; if (iTag == TAG_Flower1) { times = arc4random() % 7 + 3;//花瓣下落的时间 roTime = 0.8;//花瓣摆动一次时间 fAngle1 = -80;//花瓣摆动角度 fAngle2 = 80;//摆动角度 } else { times = arc4random() % 7 + 3; roTime = 1.8; fAngle1 = -100; fAngle2 = 100; } // CCLog("Down Time =======> %f", times); //随机生成花瓣横向偏移值 //srand((unsigned)time(NULL)); int randPos = arc4random() % ((int)CCDirector::sharedDirector()->getWinSize().width) + 400; // CCLog("Shift_flower======>%d", randPos); //运动到的位置 int movPos = CCDirector::sharedDirector()->getWinSize().width - randPos; int hori_shift = (arc4random() % 2) * 150;// 再次横向偏移, 或者有偏移,或者无随机 // CCLOG("movPos ============>%d hori_shift ===========> %d", movPos, hori_shift); // CCMoveTo *moveTo = CCMoveTo::create(times, ccp(CCDirector::sharedDirector()->getWinSize().width - iRandPos, 30)); CCMoveTo *moveTo = CCMoveTo::create(times, ccp(movPos + hori_shift, -550)); CCCallFuncN *actDone = CCCallFuncN::create(this, callfuncN_selector(SGAnnouncementLayer::restartFlower)); CCFiniteTimeAction *putdown = CCSequence::create(moveTo, actDone, NULL); //花瓣旋转动作 CCRotateBy *rotaBy1 = CCRotateBy::create(roTime, fAngle1); CCRotateBy *rotaBy2 = CCRotateBy::create(roTime, fAngle2); //花瓣翻转动作 spriteFlower->setVertexZ(60);//防止出现遮挡 //from internet CCOrbitCamera * orbit = CCOrbitCamera::create(8, 1, 0, 0, 360, 45, 0); //让花执行三维翻转的动作 CCRepeat *fz3d = CCRepeat::create(orbit, -1);//不停进行翻转花瓣翻转的动作 //类似淡入淡出 CCEaseInOut *ease1 = CCEaseInOut::create(rotaBy1, 3); CCEaseInOut *ease2 = CCEaseInOut::create(rotaBy2, 3); //摆动动作合成 CCFiniteTimeAction *seq2 = CCSequence::create(ease1, ease2, NULL); CCRepeat *blink = CCRepeat::create(seq2, -1);//合成对应摆动作 //同时执行所有动作 spriteFlower->runAction(CCSpawn::create(putdown, blink, fz3d, NULL)); }