Example #1
0
void GameScene::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){
    
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCPoint touchPoint = pDirector->convertToGL(pTouch->getLocationInView());
  
    CCNode* pCard = this->getChildByTag(nextNumber);
    if (!pCard)
    {
        return;
    }
    
    CCRect cardRect = pCard->boundingBox();
    if (cardRect.containsPoint(touchPoint)) {
        CCSprite* pNewCard = CCSprite::create("card_backside.png");
        pNewCard->setPosition(pCard->getPosition());
        this->addChild(pNewCard);
        
        pCard->removeFromParentAndCleanup(true);
        
        if (nextNumber >= 25)
        {
            this->unschedule(schedule_selector(GameScene::measureGametime));
            showHighScoreLabel();
            return;
        }
        nextNumber++;
    }
    
    //CCLog("x: %f, y:%f", touchPoint.x, touchPoint.y);
}
//-------------------------------------------------------------------------
ENUM_WidgetTouchModel FKCW_UIWidget_Layout::onTouchBegan(CCTouch* pTouch)
{
	m_pSelectedWidget = NULL;
	m_eSelectedWidgetTouchModel = eWidgetTouchNone;

	CCPoint tNodePoint = convertToNodeSpace(pTouch->getLocation());
	if( m_pChildren && m_pChildren->count() > 0 )
	{
		CCObject* pObject = NULL;
		CCARRAY_FOREACH_REVERSE( m_pChildren, pObject )
		{
			CCNode* pNode = dynamic_cast<CCNode*>(pObject);
			FKCW_UIWidget_Widget* pWidget = dynamic_cast<FKCW_UIWidget_Widget*>(pObject);
			if( pWidget && pNode->isVisible() && pWidget->isEnabled() && pWidget->isTouchEnabled() )
			{
				if( pNode->boundingBox().containsPoint(tNodePoint) )
				{
					m_eSelectedWidgetTouchModel = pWidget->executeTouchBeganHandler(pTouch);
					if( m_eSelectedWidgetTouchModel == eWidgetTouchNone )
					{
						m_pSelectedWidget = NULL;
						m_eSelectedWidgetTouchModel = eWidgetTouchNone;
					}
					else
					{
						m_pSelectedWidget = pWidget;
						return m_eSelectedWidgetTouchModel;
					}
				}
			}
		}
Example #3
0
bool CWidgetLayout::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
	if( m_bTouchEnabled && m_bVisible && m_pChildren && m_pChildren->count() > 0 )
	{
		CCPoint touchPointInView = convertToNodeSpace(pTouch->getLocation());
		if( m_pChildren && m_pChildren->count() > 0 )
		{
			CCObject* pObject = NULL;
			CCARRAY_FOREACH_REVERSE( m_pChildren, pObject )
			{
				CCNode* pNode = dynamic_cast<CCNode*>(pObject);
				CWidget* pWidget = dynamic_cast<CWidget*>(pObject);
				if( pWidget && pNode->isVisible() && pWidget->isEnabled() && pWidget->isTouchEnabled() )
				{
					if( pNode->boundingBox().containsPoint(touchPointInView) )
					{
						if( pWidget->executeTouchBeganHandler(pTouch) != eWidgetTouchNone )
						{
							m_pSelectedWidget = pWidget;
							m_bIsTouched = true;
							m_fTouchedDuration = 0.0f;
							return true;
						}
					}
				}
			}
KDvoid JewelController::touchMoved ( APSGraphic* pGraphic, const APSTouch& tTouch ) 
{
    // calculate touched position in symbol
    CCPoint  tPosition  = m_pSymbol->convertPositionFromParentNode ( tTouch.getPosition ( ) );    
    CCNode*  pJewelNode = pGraphic->getNode ( );
    
    // change jewel graphic node position to touched position.
    pJewelNode->setPosition ( tPosition );
    
    // get the rectangular box of jewel node
    CCRect  tJewelBox = pJewelNode->boundingBox ( );
    
    // get the rectangular box of boy node.
    CCRect  tBoyBox = m_pBoyGraphic->getNode ( )->boundingBox ( );
    
    // check intersection of the two boxes.
	if (  tJewelBox.intersectsRect ( tBoyBox ) )
	{
        APSActionGroup*  pShakeBoyAction =  (APSActionGroup*) m_pSymbol->getResourceForTag ( "ShakeBoy" );
        // trigger 'ShakeBoy' action group only if it is currently not running.
        if ( !pShakeBoyAction->getRunning ( ) )
		{
            pShakeBoyAction->trigger ( );
        }
    }
}
Example #5
0
void SecondScene::onTouchClicked(CCTouch *touch, CCEvent *event, CCPoint location)
{
	CCLOGFUNC();
	
	CCNode *image = this->getChildByTag(kTagSecondSceneImage);
	
	if (image->boundingBox().containsPoint(location))
	{
		this->popScene();
	}
}
Example #6
0
void MainLayer::update(float delta)
{
	if (!disappearing)
	{
		CCNode *left = this->getChildByTag(TAG_LEFT);
		CCNode *right = this->getChildByTag(TAG_RIGHT);
		if (left && right)
		{

			CCRect leftRect = left->boundingBox();
			CCRect rightRect = right->boundingBox();
			leftRect.size = leftRect.size * 0.85f;
			rightRect.size = rightRect.size * 0.8f;
			if (leftRect.intersectsRect(rightRect))
			{
				disappearing = true;
				/*爆炸*/
				playDropAnimation();
			}
			else if (left->getPosition().x > right->getPosition().x)
			{
				disappearing = true;
				leftJumping = false;
				rightJumping = false;
				//计分
				Counter *counter = Counter::sharedCounter();
				(*counter)++;
				this->reCreateNewRole();
//			left->runAction(CCFadeOut::create(0.8f));
//			right->runAction(
//					CCSequence::createWithTwoActions(CCFadeOut::create(0.8f),
//							CCCallFunc::create(this,
//									callfunc_selector(
//											MainLayer::reCreateNewRole))));
			}
		}
	}

}
//check if any node is clicked.
CCNode *VEScrollView::touchCheck(CCPoint touchPoint)
{
    CCArray *children = m_pContainer->getChildren();

    if(children == NULL)
        return NULL;

    CCPoint np = m_pContainer->convertToNodeSpace(touchPoint);
    for(int i=0; i<children->count(); i++)
    {
        CCNode *node = (CCNode*)children->objectAtIndex(i);
        CCRect box = node->boundingBox();
        if(node->boundingBox().containsPoint(np)) {
            CCLOG("click node %d %p\n", i, node);
            if (m_touchListener && m_touchHandler)
                (m_touchListener->*m_touchHandler)(node);
            return node;
        }
    }

    return NULL;
}
Example #8
0
void GameScene::getTouchBlockTag( CCPoint touchPoint, int &tag, kBlock &blockType )
{
    for( int x = 0; x < MAX_BLOCK_X; x++ ) {
        for ( int y = 0; y < MAX_BLOCK_Y; y++ ) {
            int currentTag = getTag( x, y );
            CCNode* node = m_background->getChildByTag( currentTag );
            if ( node && node->boundingBox().containsPoint( touchPoint ) ) {
                tag = currentTag;
                blockType = ((BlockSprite*)node)->getBlockType();
                return;
            }
        }
    }
}
void GameScene::ccTouchMoved(CCTouch* pTouch, CCEvent* pEvent)
{
    CCLOG("ccTouchMoved");
    CCPoint touchPoint = background->convertTouchToNodeSpace(pTouch);
    TouchedBlock touched_block = getTouchedBlock(touchPoint);
    if (currentTag != 0 && touchPoint.x >= (blockAreaStartPoint.x - blockSize / 2) && touchPoint.y >= (blockAreaStartPoint.y - blockSize / 2) && touchPoint.x <= (blockAreaEndPoint.x + blockSize / 2) && touchPoint.y <= (blockAreaEndPoint.y + blockSize / 2))
    {
        CCNode* tmp_current = background->getChildByTag(tmpCurrentTag);
        tmp_current->setPosition(touchPoint);
        if (previousTag != 0)
        {
            CCNode* previousBlock = background->getChildByTag(previousTag);
            if (!previousBlock->boundingBox().containsPoint(touchPoint))
            {
                previousTag = 0;
            }
        }

        if (touched_block.tag != 0 && touched_block.tag != previousTag)
        {
            previousTag = touched_block.tag;
            CCNode* current = background->getChildByTag(currentTag);
            CCNode* target  = background->getChildByTag(touched_block.tag);
            
            // ブロックを入れ替える
            BlockFiledsPositionIndex target_position_idex  = getBlockFieldsPositionIndex(touched_block.tag);
            BlockFiledsPositionIndex current_position_idex = getBlockFieldsPositionIndex(currentTag);
            blockFields[target_position_idex.x][target_position_idex.y]   = (BlockSprite*)current;
            blockFields[current_position_idex.x][current_position_idex.y] = (BlockSprite*)target;

            CCPoint prePoint = getPosition(current_position_idex.x, current_position_idex.y);
            current->setPosition(getPosition(target_position_idex.x, target_position_idex.y));
            
            CCMoveTo* targetMove = CCMoveTo::create(0.2f, prePoint);
            CCPlaySE* playSe = CCPlaySE::create(kSEMoveBlock);
            CCFiniteTimeAction* moveAction = CCSpawn::create(targetMove, playSe, NULL);
            
            target->runAction(moveAction);
        }
    }
}
Example #10
0
bool SkillLayer::isTouchForMe(CCPoint touchLocation){
    CCNode* node = this->getChildByTag(1);
    CCRect rec = node->boundingBox();
    return CCRect::CCRectContainsPoint(rec, touchLocation);
}