Exemplo n.º 1
0
bool IBBTouchElement::doCCTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{
	if(m_touchListeners->count() == 0) return false;
	bool result = false;
	
	pTouch->retain();
	
	CCPoint pos = pTouch->getLocationInView();
	pos = CCDirector::sharedDirector()->convertToGL(pos);
	
	CCObject* it = NULL;
	
	CCARRAY_FOREACH(m_touchListeners, it)
	{
		CCNode* node = dynamic_cast<CCNode*>(it);
		
		node->retain();
		
		if(BBTouchEventUtils::hitTest(node, pTouch))
		{
						
			result = m_blockTouchFlow;
					
			onTouchPress(node, pTouch);
			BBTouchEventUtils::press(node, pos);
		}
	}
Exemplo n.º 2
0
bool CCTile3DFrameBuffer::handleProjectedTouch(const CCCameraProjectionResults &cameraProjectionResults,
                                               const CCCollideable *hitObject,
                                               const CCVector3 &hitPosition,
                                               const CCScreenTouches &touch,
                                               const CCTouchAction touchAction)
{
    if( collisionsEnabled == false )
    {
        return false;
    }

    if( sceneControlsActive )
    {
        return handleSceneTouch( cameraProjectionResults, hitObject, hitPosition, touch, touchAction );
    }

    if( hitObject == this &&
       ( touchAction == touch_pressed || ( touchMovementAllowed && CCControls::TouchActionMoving( touchAction ) ) ) )
    {
        if( touching == false )
        {
            touching = true;
            touchingTime = 0.0f;
            onTouchPress();
        }
    }

    if( touching )
    {
        const float maxTimeHeld = 0.125f;

        if( touchAction == touch_pressed )
        {
            if( touch.timeHeld >= maxTimeHeld )
            {
                CCVector3 relativeHitPosition;
                relativeHitPosition.x = hitPosition.x - position.x;
                relativeHitPosition.y = hitPosition.y - position.y;
                float x = relativeHitPosition.x / collisionBounds.x;
                float y = relativeHitPosition.y / collisionBounds.y;
                touchActionPressed( x, y, touch, touchAction );
            }
        }
        else if( touchMovementAllowed && CCControls::TouchActionMoving( touchAction ) )
        {
            if( hitObject != this )
            {
                return handleProjectedTouch( cameraProjectionResults, hitObject, hitPosition, touch, touch_lost );
            }
            else
            {
                CCVector3 relativeHitPosition;
                relativeHitPosition.x = hitPosition.x - position.x;
                relativeHitPosition.y = hitPosition.y - position.y;
                float x = relativeHitPosition.x / collisionBounds.x;
                float y = relativeHitPosition.y / collisionBounds.y;
                touchActionPressed( x, y, touch, touchAction );
            }
        }
        else
        {
            // Ensure we have a good touch release
            if( touchAction == touch_released )
            {
                if( touchMovementAllowed == false )
                {
                    const float absDeltaX = fabsf( touch.totalDelta.x );
                    const float absDeltaY = fabsf( touch.totalDelta.y );
                    if( absDeltaX > CCControls::GetTouchMovementThreashold().x || absDeltaY > CCControls::GetTouchMovementThreashold().y )
                    {
                        return handleProjectedTouch( cameraProjectionResults, hitObject, hitPosition, touch, touch_lost );
                    }
                }

                // If we have a good first touch, register it.
                CCVector3 relativeHitPosition;
                relativeHitPosition.x = hitPosition.x - position.x;
                relativeHitPosition.y = hitPosition.y - position.y;
                float x = relativeHitPosition.x / collisionBounds.x;
                float y = relativeHitPosition.y / collisionBounds.y;
                touchActionPressed( x, y, touch, touch_pressed );
            }

            touching = false;
            touchActionRelease( touchAction );

            if( touchAction == touch_released )
            {
                return true;
            }
        }
    }

    return false;
}