void ActorLayer::PickupItemFromField(flownet::ActorID playerID, flownet::ItemID itemID) { ActorNode* actor = this->FindActorNode(playerID); ItemNode* item = this->FindItemNode(itemID); CCJumpTo* jumpTo = CCJumpTo::create(0.3, actor->GetMidPosition(), 30, 1); CCDelayTime* delay = CCDelayTime::create(0.3); CCCallFuncO* remove = CCCallFuncO::create(this, callfuncO_selector(ActorLayer::RemoveItem), item); CCSequence* sequence = CCSequence::create(jumpTo, delay, remove, NULL); sequence->setTag(ActionType_Animation); item->runAction(sequence); // TO DO : display effect for acquiring item }
void Object::performAnimation(string name, SEL_CallFunc func){ if (this->getCurrentObjectState() == ObjectStateDead && name.compare("Dead") != 0) { return; } CCSpriteBatchNode *currentSpriteBatchNode = m_pobBatchNode; CCSpriteBatchNode *newSpriteBatchNode = NULL; // Get the action pair by key name CCArray *actionPair = (CCArray *)actionsHashes->objectForKey(name); // If the action pair does not exist, return early if (!actionPair) { return; } newSpriteBatchNode = (CCSpriteBatchNode *)actionPair->objectAtIndex(1); ActionNode *actionNode = (ActionNode *)actionPair->objectAtIndex(0); this->stopActionByTag(ACTION_ANIMATION_TAG); // If required spriteBatchNode is different from current, replace it if (currentSpriteBatchNode != newSpriteBatchNode) { this->removeFromParentAndCleanup(false); this->setTexture(actionNode->getFirstSpriteFrame()->getTexture()); this->setTextureRect(actionNode->getFirstSpriteFrame()->getRect()); newSpriteBatchNode->addChild(this); } if (func != NULL) { CCAssert(dynamic_cast<CCRepeatForever*>(actionNode->getAnimation()) == NULL, "Not able to call function for CCRepeatForever action."); // Create animation followed by a function call CCSequence *seq = CCSequence::createWithTwoActions(actionNode->getAnimation(), CCCallFunc::create(this, func)); seq->setTag(ACTION_ANIMATION_TAG); this->runAction(seq); } else { // Run the action actionNode->getAnimation()->setTag(ACTION_ANIMATION_TAG); this->runAction(actionNode->getAnimation()); } // Run AI in this action { if (actionPair->count() > 2) { CCArray *AIActions = (CCArray *)actionPair->objectAtIndex(2); CCLOG("%s is running AI, total AIAction count: %d", identifier.c_str(), AIActions->count()); for (int i = 0; i < AIActions->count(); i++) { CCAction *action = (CCAction*)AIActions->objectAtIndex(i); this->runAction(action); } } } }
void CScrollView::setContentOffsetInDurationWithoutCheck(const CCPoint& tOffset, float fDuration) { m_pContainer->stopActionByTag(CSCROLLVIEW_MOVE_ACTION_TAG); CCSequence* pSequence = CCSequence::create( CCMoveTo::create(fDuration, tOffset), CCCallFunc::create(this, callfunc_selector(CScrollView::stoppedAnimatedScroll)), NULL); pSequence->setTag(CSCROLLVIEW_MOVE_ACTION_TAG); m_pContainer->runAction(pSequence); perpareAnimatedScroll(); this->onScrolling(); this->executeScrollingHandler(this); }
void GameEntityView::doShake() { //CCLog("shake entity view "); #define SHAKE_TAG 0xDEADBEEF if( getActionByTag(SHAKE_TAG) == NULL ) { CCSequence* shake = CCSequence::create( CCRotateBy::create(0.1f, 10, 0), CCRotateBy::create(0.2f, -20, 0), CCRotateBy::create(0.1f, 10, 0), NULL); shake->setTag(SHAKE_TAG); runAction(shake); } }
void Witch::jump() { setVelocity(1000); mIsJump = true; mWitch->stopActionByTag(1); mWitch->setRotation(0); auto callback = CallFunc::create([&](){slowDrop(); }); CCActionInterval* action = CCRotateBy::create(0.3f, 360); CCSequence* sqn = CCSequence::create(action, callback, NULL); sqn->setTag(1); mWitch->runAction(sqn); SimpleAudioEngine::sharedEngine()->playEffect(SE::Jump); }
void ActorLayer::KnockBackActor(flownet::ActorID actorID, flownet::POINT currentPosition, flownet::POINT knockbackDestination) { ActorNode* knockbackObject = this->FindActorNode(actorID); ASSERT_DEBUG(knockbackObject); const float KNOCKBACK_DURATION = currentPosition.DistanceTo(knockbackDestination) / Actor_KnockBack_Speed; knockbackObject->StopAnimationActions(); CCFiniteTimeAction* animateAttacked = CCCallFunc::create(knockbackObject, callfunc_selector(ActorNode::AnimateAttacked)); CCFiniteTimeAction* actionMove = CCEaseOut::create(CCMoveTo::create(KNOCKBACK_DURATION, PointConverter::Convert(knockbackDestination)), 4.f); CCFiniteTimeAction* actionMoveDone = CCCallFunc::create( knockbackObject, callfunc_selector(ActorNode::AnimateIdle)); CCSequence* sequence = CCSequence::create(animateAttacked, actionMove, actionMoveDone, NULL); sequence->setTag(ActionType_Animation); knockbackObject->runAction(sequence); }
void GoBattleLayer::moveOutTouchUICompent() { if (m_pBgSprite->getActionByTag(MOVEIN_TAG)) { m_pBgSprite->stopAllActions(); m_pBgSprite->setPosition(ccp(0.0, 615.0f + m_pGameState->getBottomOffset())); CCSequence* pMoveOUtAction = CCSequence::create(CCMoveTo::create(ANIMATION_DURING, ccp(0, 975.0f + m_pGameState->getBottomOffset())), CCCallFunc::create(this, callfunc_selector(GoBattleLayer::moveOutCallback)), NULL); pMoveOUtAction->setTag(MOVEOUT_TAG); m_pBgSprite->runAction(pMoveOUtAction); return; } if (!m_pBgSprite->getActionByTag(MOVEOUT_TAG)) { CCSequence* pMoveOUtAction = CCSequence::create(CCMoveTo::create(ANIMATION_DURING, ccp(0, 975.0f + m_pGameState->getBottomOffset())), CCCallFunc::create(this, callfunc_selector(GoBattleLayer::moveOutCallback)), NULL); pMoveOUtAction->setTag(MOVEOUT_TAG); m_pBgSprite->runAction(pMoveOUtAction); } m_isInScreen = false; }
void CANavigationController::pushViewController(CAViewController* viewController, bool animated) { if (this->getView()->getSuperview() == NULL) { return; } if (m_pContainer->getActionByTag(0)) { return; } float x = m_pContainer->getFrame().size.width; CAViewController* lastViewController = m_pViewControllers.back(); lastViewController->getView()->setFrame(CCRect(-x, 0, 0, 0)); viewController->retain(); viewController->m_pNavigationController = this; m_pViewControllers.push_back(viewController); if (viewController->getNavigationBarItem() == NULL && viewController->getTitle().compare("") != 0) { viewController->setNavigationBarItem(CANavigationBarItem::create(viewController->getTitle())); } m_pNavigationBar->pushItem(viewController->getNavigationBarItem()); viewController->addViewFromSuperview(m_pContainer); if (animated) { m_pContainer->stopAllActions(); m_pContainer->setFrame(CCRect(x, m_pContainer->getFrame().origin.y, 0, 0)); CCDelayTime* delayTime = CCDelayTime::create(0.1f); CCMoveBy* moveBy = CCMoveBy::create(0.3f, CCPoint(-x, 0)); CCEaseSineOut* easeBack = CCEaseSineOut::create(moveBy); CCCallFunc* finish = CCCallFunc::create(this, callfunc_selector(CANavigationController::pushViewControllerFinish)); CCSequence* actions = CCSequence::create(delayTime, easeBack, finish, NULL); m_pContainer->runAction(actions); actions->setTag(0); } else { this->pushViewControllerFinish(); } }
CAViewController* CANavigationController::popViewControllerAnimated(bool animated) { if (m_pViewControllers.size() == 1) { return NULL; } if (m_pContainer->getActionByTag(0)) { return NULL; } unsigned int index = m_pViewControllers.size() - 2; CAViewController* showViewController = m_pViewControllers.at(index); showViewController->getView()->setFrame(CCRectZero); m_pContainer->addSubview(showViewController->getView()); CAViewController* backViewController = m_pViewControllers.back(); float x = m_pContainer->getFrame().size.width; backViewController->getView()->setFrame(CCRect(x, 0, 0, 0)); if (animated) { m_pContainer->stopAllActions(); m_pContainer->setFrameOrigin(CCPoint(-x, m_pContainer->getFrameOrigin().y)); CCDelayTime* delayTime = CCDelayTime::create(0.2f); CCFrameOrginTo* moveTo = CCFrameOrginTo::create(0.4f, CCPoint(0, m_pContainer->getFrameOrigin().y)); CCEaseSineOut* easeBack = CCEaseSineOut::create(moveTo); CCCallFunc* finish = CCCallFunc::create(this, callfunc_selector(CANavigationController::popViewControllerFinish)); CCSequence* actions = CCSequence::create(delayTime, easeBack, finish, NULL); m_pContainer->runAction(actions); actions->setTag(0); } else { this->popViewControllerFinish(); } return backViewController; }
void CANavigationController::replaceViewController(CrossApp::CAViewController *viewController, bool animated) { if (this->getView()->getSuperview() == NULL) { return; } if (m_pContainer->getActionByTag(0)) { return; } float x = m_pContainer->getFrame().size.width; CAViewController* lastViewController = m_pViewControllers.back(); lastViewController->getView()->setFrame(CCRect(-x, 0, 0, 0)); viewController->retain(); viewController->m_pNavigationController = this; m_pViewControllers.insert(m_pViewControllers.end()-1, viewController); viewController->addViewFromSuperview(m_pContainer); if (animated) { m_pContainer->stopAllActions(); m_pContainer->setFrameOrigin(CCPoint(x, m_pContainer->getFrameOrigin().y)); CCDelayTime* delayTime = CCDelayTime::create(0.5f); CCFrameOrginTo* moveTo = CCFrameOrginTo::create(0.4f, CCPoint(0, m_pContainer->getFrameOrigin().y)); CCEaseSineOut* easeBack = CCEaseSineOut::create(moveTo); CCCallFunc* finish = CCCallFunc::create(this, callfunc_selector(CANavigationController::replaceViewControllerFinish)); CCSequence* actions = CCSequence::create(delayTime, easeBack, finish, NULL); m_pContainer->runAction(actions); actions->setTag(0); } else { this->replaceViewControllerFinish(); } }
bool CATableView::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { if (m_pTouches->count() > 0) return false; if (!CAScrollView::ccTouchBegan(pTouch, pEvent)) return false; if (m_bAllowsSelection && this->isScrollWindowNotOutSide() == false) { CCPoint point = m_pContainer->convertTouchToNodeSpace(pTouch); std::deque<CATableViewCell*>::iterator itr; for (itr=m_pTableCells.begin(); itr!=m_pTableCells.end(); itr++) { CATableViewCell* cell = *itr; if (cell->getFrame().containsPoint(point)) { CC_BREAK_IF(cell->isDisabled()); m_pHighlightedTableCells = cell; CC_BREAK_IF(cell->isSelected()); CCDelayTime* delayTime = CCDelayTime::create(0.1f); CCCallFunc* func = CCCallFunc::create(cell, callfunc_selector(CATableViewCell::setControlStateHighlighted)); CCSequence* actions = CCSequence::create(delayTime, func, NULL); actions->setTag(0xffff); this->runAction(actions); break; } } } m_tBeginPoint = pTouch->getLocation(); return true; }
CCObject* CCSequence::copyWithZone(CCZone *pZone) { CCZone* pNewZone = NULL; CCSequence* pCopy = NULL; if(pZone && pZone->m_pCopyObject) { //in case of being called at sub class pCopy = (CCSequence*)(pZone->m_pCopyObject); } else { pCopy = new CCSequence(); pZone = pNewZone = new CCZone(pCopy); } CCActionInterval::copyWithZone(pZone); pCopy->initOneTwo((CCFiniteTimeAction*)(m_pActions[0]->copy()->autorelease()), (CCFiniteTimeAction*)(m_pActions[1]->copy()->autorelease())); CC_SAFE_DELETE(pNewZone); return pCopy; }
void AwaiterInfoNode::DisplayChatMessage(const STRING& message) { const INT ChatBallonTag = 67; m_ChatBalloon->stopActionByTag(ChatBallonTag); m_ChatBalloon->setOpacity(233); m_ChatBalloon->setVisible(true); m_ChatLabel->setVisible(true); m_ChatLabel->setOpacity(233); m_ChatLabel->setString(message.c_str()); CCScaleTo* popEffect = CCScaleTo::create(0.3f, 1.3f); CCScaleTo* popReverse = CCScaleTo::create(0.3f, 1.f); CCDelayTime* delayTime = CCDelayTime::create(5.f); CCFadeOut* fadeOut = CCFadeOut::create(2.f); CCHide* hide = CCHide::create(); CCSequence* popUpSequence = CCSequence::create(popEffect, popReverse, delayTime, fadeOut, hide, nullptr); popUpSequence->setTag(ChatBallonTag); m_ChatBalloon->runAction(popUpSequence); }
void GameScene::birdFlyLogic() { M3AudioManager::shareInstance()->playSound(SOUND_FLY); CCSprite* bird = (CCSprite*)getChildByTag(TAG_BIRD); bird->stopActionByTag(100); bird->setRotation(340); CCMoveBy* moveUp = CCMoveBy::create(0.2f, ccp(0, bird->getContentSize().height * 1.25f)); CCEaseOut* upEout = CCEaseOut::create(moveUp, 2.25f); CCDelayTime* delay = CCDelayTime::create(0.2f); CCRotateBy* rotate = CCRotateBy::create(0.35f, 75); CCSequence* seq0 = CCSequence::create(delay, rotate, NULL); CCMoveBy* moveDown = CCMoveBy::create(1.5f, ccp(0, -screenSize.height * 1.5f)); CCEaseIn* downIn = CCEaseIn::create(moveDown, 1.95f); CCSpawn* spawn = CCSpawn::create(seq0, downIn, NULL); CCSequence* seq = CCSequence::create(upEout, spawn, NULL); seq->setTag(100); bird->runAction(seq); }
void CAIndicator::setIndicator(const CCSize& parentSize, const CCRect& childrenFrame) { CCScale9Sprite* indicator = dynamic_cast<CCScale9Sprite*>(m_pIndicator); int x = (int)indicator->getCenterOrigin().x * 10; int y = (int)indicator->getCenterOrigin().y * 10; if (m_eType == CAIndicatorTypeHorizontal) { float size_scale_x = parentSize.width / childrenFrame.size.width; size_scale_x = MIN(size_scale_x, 1.0f); float lenght_scale_x = parentSize.width / 2 - childrenFrame.origin.x; lenght_scale_x /= childrenFrame.size.width; CCSize size = m_obContentSize; size.width *= size_scale_x; if (lenght_scale_x < size_scale_x / 2) { size.width *= lenght_scale_x / (size_scale_x / 2); } if (1 - lenght_scale_x < size_scale_x / 2) { size.width *= (1 - lenght_scale_x) / (size_scale_x / 2); } size.width = MAX(size.height, size.width); indicator->setPreferredSize(size); CCPoint point = m_obContentSize; point.y *= 0.5f; point.x *= lenght_scale_x; point.x = MAX(point.x, size.width/2); point.x = MIN(point.x, m_obContentSize.width - size.width/2); indicator->setCenterOrigin(point); } else if (m_eType == CAIndicatorTypeVertical) { float size_scale_y = parentSize.height / childrenFrame.size.height; size_scale_y = MIN(size_scale_y, 1.0f); float lenght_scale_y = parentSize.height / 2 - childrenFrame.origin.y; lenght_scale_y /= childrenFrame.size.height; CCSize size = m_obContentSize; size.height *= size_scale_y; if (lenght_scale_y < size_scale_y / 2) { size.height *= lenght_scale_y / (size_scale_y / 2); } if (1 - lenght_scale_y < size_scale_y / 2) { size.height *= (1 - lenght_scale_y) / (size_scale_y / 2); } size.height = MAX(size.height, size.width); indicator->setPreferredSize(size); CCPoint point = m_obContentSize; point.x *= 0.5f; point.y *= lenght_scale_y; point.y = MAX(point.y, size.height/2); point.y = MIN(point.y, m_obContentSize.height - size.height/2); indicator->setCenterOrigin(point); } do { if (x == (int)indicator->getCenterOrigin().x * 10 && y == (int)indicator->getCenterOrigin().y * 10) { CC_BREAK_IF(indicator->getActionByTag(0xfff)); CC_BREAK_IF(indicator->getOpacity() < 255); CCDelayTime* delayTime = CCDelayTime::create(0.2f); CCFadeOut* fadeOut = CCFadeOut::create(0.3f); CCEaseSineOut* easeSineOut = CCEaseSineOut::create(fadeOut); CCSequence* actions = CCSequence::create(delayTime, easeSineOut, NULL); actions->setTag(0xfff); this->runAction(actions); } else { CC_BREAK_IF(indicator->getOpacity() == 255); indicator->stopAllActions(); this->setOpacity(255); } } while (0); }
void CTopLayer::updateRoleProperty(const TMessage& tMsg) { UserData *user = DataCenter::sharedData()->getUser()->getUserData(); CCScaleTo* sc1 = CCScaleTo::create(0.15f,1.3f); CCScaleTo* sc2 = CCScaleTo::create(0.35f,1.0f); CCSequence* sqes = CCSequence::create(sc1,sc2,nullptr); if (user->getCoin()!=atoi(m_coinLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_coinLabel); prolab->changeValueTo(user->getCoin(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_coinLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(130); int coin = user->getCoin()-atoi(m_coinLabel->getString()); changeLabel(label, coin); } if (user->getRoleGold()!=atoi(m_moneyLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_moneyLabel); prolab->changeValueTo(user->getRoleGold(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_moneyLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(140); int coin = user->getRoleGold()-atoi(m_moneyLabel->getString()); changeLabel(label, coin); } /* if (user->getRoleFood()!=atoi(m_foodLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_foodLabel); prolab->changeValueTo(user->getRoleFood(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_foodLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(170); int coin = user->getRoleFood()-atoi(m_foodLabel->getString()); changeLabel(label, coin); } */ if (user->getFriends()!=atoi(m_foodLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_foodLabel); prolab->changeValueTo(user->getFriends(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_foodLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(170); int coin = user->getFriends()-atoi(m_foodLabel->getString()); changeLabel(label, coin); } CLabel *action = (CLabel*)(m_ui->findWidgetById("action")); if (user->getRoleAction()!=atoi(action->getString())) { CCSequence* sqes2 = (CCSequence*)sqes->copy(); action->runAction(sqes2); action->setString(CCString::createWithFormat("%d/%d",user->getRoleAction(), user->getActionLimit())->getCString()); } }