Пример #1
0
    void TextTip::onExit()
    {
        unscheduleAllCallbacks();
        unscheduleUpdate();

        Layout::onExit();
    }
Пример #2
0
void ScrollView::scrollToPage(int nPage)
{
    // 关闭CCScrollView中的自调整
    unscheduleAllCallbacks();
    
    Vec2 oOffset = getContentOffset();
    // 调整位置
    Vec2 adjustPos= Vec2(-_cellSize.width*nPage,0);
    
    // 调整动画时间
    float adjustAnimDelay= adjustPos.getDistance(oOffset)/_adjustSpeed;
    
    // 调整位置
    setContentOffsetInDuration(adjustPos, adjustAnimDelay);
    
    if (nPage!=_prePage)
    {
        this->setTouchEnabled(false);
        schedule(schedule_selector(ScrollView::onScrollEnd),adjustAnimDelay,0,0.0f);
        _prePage=nPage;
        
        if(_delegate)
            _delegate->scrollViewMoveToPage(nPage);
    }
}
Пример #3
0
void ReinforceSoldier2::attackMonster(float dt)
{
	if(nearestMonster!=NULL && nearestMonster->getCurrHp()>0){
		if (!checkDirectionForMonster()){
			nearestMonster->setState(stateAttackLeft);
		}else{
			nearestMonster->setState(stateAttackRight);
		}
		setState(SoldierStateHit);
		auto monsterCurrHp = nearestMonster->getCurrHp();
		auto SoldierHp = this->getCurrHp();

		monsterCurrHp =  monsterCurrHp - this->getForce();

		if(nearestMonster->getState()!=stateFrozen)
			SoldierHp =  SoldierHp - nearestMonster->getForce();

		if(monsterCurrHp <= 0){
			monsterCurrHp = 0;
		}
		if(SoldierHp <= 0){
			SoldierHp = 0;
		}
		nearestMonster->setCurrHp( monsterCurrHp );
		this->setCurrHp(SoldierHp);

		nearestMonster->getHpBar()->setPercentage((monsterCurrHp/nearestMonster->getMaxHp())*100);
		this->getHpBar()->setPercentage((SoldierHp/this->getMaxHp())*100);

		if(monsterCurrHp == 0){
			unschedule(schedule_selector(ReinforceSoldier2::attackMonster));
			//GameManager::getInstance()->monsterVector.eraseObject(nearestMonster);
			nearestMonster->death();
			if(this->getCurrHp()>0)
				runToLocation(location);
		}
		if(SoldierHp == 0){
			lastState = SoldierStateDeath;
			setState(SoldierStateDeath);
			unscheduleAllCallbacks();
			stopAllActions();
			baseSprite->stopAllActions();
			hpBgSprite->setVisible(false);
			if(nearestMonster != NULL && nearestMonster->getCurrHp()>0){
				nearestMonster->restartWalking();
				nearestMonster->setIsAttacking(false);
			}
			baseSprite->runAction(Sequence::create(
				FadeOut::create(1.0f)
				,CallFuncN::create(CC_CALLBACK_0(ReinforceSoldier2::removeFromParent, this))
				,NULL));
		}
	}else{
		unschedule(schedule_selector(ReinforceSoldier2::attackMonster));
		if(this->getCurrHp()>0)
			runToLocation(location);
	}
}
ControlStepper::~ControlStepper()
{
    unscheduleAllCallbacks();

    CC_SAFE_RELEASE(_minusSprite);
    CC_SAFE_RELEASE(_plusSprite);
    CC_SAFE_RELEASE(_minusLabel);
    CC_SAFE_RELEASE(_plusLabel);
}
Пример #5
0
void SchedulerUpdate::removeUpdates(float dt)
{
    auto& children = getChildren();

    for (auto& c : children)
    {
        auto obj = static_cast<Ref*>(c);
        auto node = static_cast<Node*>(obj);
        
        if (! node)
        {
            break;
        }
        node->unscheduleAllCallbacks();
    }
}
Пример #6
0
bool  Scene101::onTouchBegan(cocos2d::Touch *pTouch, cocos2d::Event *pEvent)//觸碰開始事件
{
	Point touchLoc = pTouch->getLocation();
	if (rectCuber.containsPoint(touchLoc)) {

	}
	if (rectReplay.containsPoint(touchLoc)) {

	}
	if (rectReturn.containsPoint(touchLoc)) {
		unscheduleAllCallbacks();
		Director::getInstance()->end();
	}

	return true;
}
Пример #7
0
bool UINumberPicker::onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *unused_event)
{
    do
    {
        CC_BREAK_IF(!isVisible());
        
        CC_BREAK_IF(m_pTouches.size() > 2);
        
        CC_BREAK_IF(m_bTouchMoved);
        // scrolling,手指移动多少距离,内容区域也移动多少,同步执行 CCScrollView
        //当前坐标转成世界坐标
        const Point &location = touch->getLocationInView();
        const Point &convertedLocation = Director::getInstance()->convertToGL(location);
        
        CC_BREAK_IF(!displayRect.containsPoint(convertedLocation));
        
        unscheduleAllCallbacks();
        
        if (!containsTouchObject(m_pTouches,touch))
        {
            m_pTouches.push_back(touch);
        }
        if (m_pTouches.size() == 1)
        {
            m_tTouchPoint = convertTouchToNodeSpace(touch);
            m_bTouchMoved = false;
            
            m_bDragging = true;
            m_tScrollDistance.set(0, 0);
            m_fTouchLength = 0;
        }
        else if (m_pTouches.size() == 2)
        {
            const Point &p1 = convertTouchToNodeSpace(m_pTouches[0]);
            const Point &p2 = convertTouchToNodeSpace(m_pTouches[1]);
            m_tTouchPoint = p1.getMidpoint(p2);
            m_fTouchLength = p1.getDistance(p2);
            
            m_bDragging = false;
        }
        return true;
    }
    while (0);
    
    return false;
}
Пример #8
0
void BaseMap::updateGoldAndLife()
{
	if(GameManager::getInstance()->LIFE>0){
		playerState->setGold(GameManager::getInstance()->MONEY);
		playerState->setLife(GameManager::getInstance()->LIFE);
	}else if(isStart){
		isStart = false;
		playerState->setLife(0);
		unscheduleAllCallbacks();
		for(int i =0;i<waveFlags.size();i++){
			waveFlags.at(i)->stopRespiration();
		}
		auto failure = Failure::create(); 
		mTouchLayer->removeAllChildren();
		failure->level = getLevel();
		failure->difficulty = difficulty;
		playerState->addChild(failure,99);
	}
}
Пример #9
0
Node::~Node()
{
    CCLOGINFO( "deallocing Node: %p - tag: %i", this, _tag );

#if CC_ENABLE_SCRIPT_BINDING
    if (_updateScriptHandler && ScriptEngineManager::ShareInstance)
    {
        ScriptEngineManager::ShareInstance->getScriptEngine()->removeScriptHandler(_updateScriptHandler);
    }
#endif

    // User object has to be released before others, since userObject may have a weak reference of this node
    // It may invoke `node->stopAllAction();` while `_actionManager` is null if the next line is after `CC_SAFE_RELEASE_NULL(_actionManager)`.
    CC_SAFE_RELEASE_NULL(_userObject);

    // attributes
    CC_SAFE_RELEASE_NULL(_glProgramState);

    for (auto& child : _children)
    {
        child->_parent = nullptr;
    }

    removeAllComponents();

    CC_SAFE_DELETE(_componentContainer);

    stopAllActions();
    unscheduleAllCallbacks();
    CC_SAFE_RELEASE_NULL(_actionManager);
    CC_SAFE_RELEASE_NULL(_scheduler);

    _eventDispatcher->removeEventListenersForTarget(this);

#if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS && COCOS2D_DEBUG > 0
    _eventDispatcher->debugCheckNodeHasNoEventListenersOnDestruction(this);
#endif

    if (_running) {
        log("Node still marked as running on node destruction! Was base class onExit() called in derived class onExit() implementations?");
    }
    CC_SAFE_RELEASE(_eventDispatcher);
}
Пример #10
0
bool  Scene102::onTouchBegan(cocos2d::Touch *pTouch, cocos2d::Event *pEvent)//觸碰開始事件
{
	Point touchLoc = pTouch->getLocation();
	if (rectCuber.containsPoint(touchLoc)) {
		this->_sceneno++;
		int i = this->_sceneno, j = 0;
		while (i > 0) {
			this->_cSceneNo[8 - j] = i % 10 + 48;
			i = i / 10;
			j++;
		}
		_label1->setString(_cSceneNo);

	}
	if (rectReplay.containsPoint(touchLoc)) {

	}
	if (rectReturn.containsPoint(touchLoc)) {
		unscheduleAllCallbacks();
		Director::getInstance()->end();
	}

	return true;
}
Пример #11
0
void SchedulerUpdateAndCustom::stopSelectors(float dt)
{
    log("SchedulerUpdateAndCustom::stopSelectors");
    unscheduleAllCallbacks();
}
Пример #12
0
void SchedulerUnscheduleAll::unscheduleAll(float dt)
{
    unscheduleAllCallbacks();
}
Пример #13
0
void MenuLayerMainMenu::allowTouches(float dt)
{
    _eventDispatcher->setPriority(_touchListener, 1);
    unscheduleAllCallbacks();
    log("TOUCHES ALLOWED AGAIN");
}