コード例 #1
0
void LCWordCloudLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
	CCTouch *touch = (CCTouch *) pTouches->anyObject();
	CCPoint touchLocation = touch->locationInView( touch->view() );	
	CCPoint prevLocation = touch->previousLocationInView( touch->view() );	
	
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS )
	m_bIsMoved = true;
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID )	
	if (touchLocation.x == initialTouchLocation.x && touchLocation.y == initialTouchLocation.y) 
		m_bIsMoved = false;
	else 
		m_bIsMoved = true;
#endif

	
	touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
	prevLocation = CCDirector::sharedDirector()->convertToGL( prevLocation );
	
	CCPoint diff = ccpSub(touchLocation,prevLocation);
	
	LCVector3Container* container = LCVector3Container::makeVector3Container(diff.x, diff.y, 0);
	container->rotationWithNormalVector((LCVector3){0, 0, 1}, convertDegreeToRadian(-90));
	container->scalarMult(m_fMouseSensitivity * 0.015);
	m_tAxisVector.x += container->getVector().x;
	m_tAxisVector.y += container->getVector().y;
	
	LCVector3Container* velocityContainer = LCVector3Container::makeVector3Container(m_tAxisVector.x, m_tAxisVector.y, m_tAxisVector.z);
	if (velocityContainer->length() > m_fMaxSpeed*2.0f) {
		m_tAxisVector = velocityContainer->convertToUnitVector()->scalarMult(m_fMaxSpeed*2.0f)->getVector();
	}
}
コード例 #2
0
void RenderTextureTest::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
    CCSetIterator it = touches->begin();
    CCTouch* touch = (CCTouch*)(*it);
    CCPoint start = touch->locationInView( touch->view() );	
    start = CCDirector::sharedDirector()->convertToGL( start );
    CCPoint end = touch->previousLocationInView( touch->view() );
    end = CCDirector::sharedDirector()->convertToGL(end);

    // begin drawing to the render texture
    m_target->begin();

    // for extra points, we'll draw this smoothly from the last position and vary the sprite's
    // scale/rotation/offset
    float distance = ccpDistance(start, end);
    if (distance > 1)
    {
        int d = (int)distance;
        for (int i = 0; i < d; i++)
        {
            float difx = end.x - start.x;
            float dify = end.y - start.y;
            float delta = (float)i / distance;
            m_brush->setPosition(ccp(start.x + (difx * delta), start.y + (dify * delta)) );
            m_brush->setRotation( rand()%360 );
            float r = ((float)(rand()%50)/50.f) + 0.25f;
            m_brush->setScale( r );
            // Call visit to draw the brush, don't call draw..
            m_brush->visit();
        }
    }
    // finish drawing and return context back to the screen
    m_target->end();
}
コード例 #3
0
ファイル: MainLayer.cpp プロジェクト: x007th/2d-xDemo
void MainLayer::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent){
	CCTouch* pTouch = (CCTouch*)pTouches->anyObject();
	CCPoint touchPoint = pTouch->locationInView();
	touchPoint = CCDirector::sharedDirector()->convertToGL(touchPoint);
    
	CCPoint oldPoint = pTouch->previousLocationInView();
	oldPoint = CCDirector::sharedDirector()->convertToGL(oldPoint);
    
	CCPoint translation = ccpSub(touchPoint, oldPoint);
	CCPoint newPos = ccpAdd(this->getPosition(), translation);
	CCPoint oldPos = this->getPosition();
	this->setPosition(boundLayerPos(newPos));
    
	m_emitter->setPosition(ccpSub(m_emitter->getPosition(), ccpSub(boundLayerPos(newPos), oldPos)));
}
コード例 #4
0
void TestController::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);
    CCPoint p1 =	touch->previousLocationInView(touch->view());
    CCPoint p2 =	touch->locationInView(touch->view());
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    float x = m_pItmeMenu->getPosition().x + (p2.x - p1.x) * 2;
    if(x>= 0)
        x = 0;
    else if(x <= -m_pItmeMenu->getContentSize().width)
        x = -m_pItmeMenu->getContentSize().width;

    m_pItmeMenu->setPosition(CCPointMake(x,0));
}
コード例 #5
0
//-----------------------------------------------------------
//
//
void CMiniGameGamblingLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
	if( g_pPetDataBlock->petmoney < 200 )
	{
		string utf81,utf82;
		CChineseCode::GB2312ToUTF_8( utf81, (char*)message_nomoney[g_iCurLanguageIndex], 256 );
		CChineseCode::GB2312ToUTF_8( utf82, (char*)message_tip[g_iCurLanguageIndex], 256 );
		CMessageBoxYes *pMessage= new CMessageBoxYes( (char*)utf81.c_str(), (char*)utf82.c_str(), NULL, NULL );
		pMessage->autorelease();
		CCDirector::sharedDirector()->getRunningScene() ->addChild( pMessage, 100 );
		return;
	}

	if( m_bIsTouch )
	{
		return;
	}

	CCSetIterator it = pTouches->begin();
	CCTouch* touch = (CCTouch*)(*it);

	CCPoint touchLocation = touch->locationInView( touch->view() );	
	CCPoint prevLocation = touch->previousLocationInView( touch->view() );	
	
	touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
	prevLocation = CCDirector::sharedDirector()->convertToGL( prevLocation );

	CCPoint pos = convertTouchToNodeSpace( touch );

	CCPoint menuPos = m_pPushBar->getPosition();

	if( CCRect::CCRectContainsPoint( CCRect( menuPos.x - 32, menuPos.y, 480 / 2, 320 / 2 ),  pos  ) )
	{
		CCActionInterval *pInterval = CCRotateBy::actionWithDuration( 0.5, 60 );
		CCActionInterval *pInterval2 = CCRotateBy::actionWithDuration( 0.5, -60 );
		m_pPushBar->runAction( CCSequence::actions( pInterval, pInterval2, CCCallFuncND::actionWithTarget( this, callfuncND_selector( CMiniGameGamblingLayer::TouchCallBack ), NULL ),  NULL ) );

		m_bIsTouch = true;
        schedule(schedule_selector(CMiniGameGamblingLayer::scheculePauseData), 0.1 );
	}


}
コード例 #6
0
ファイル: CTaskEventSubGui.cpp プロジェクト: JoeHu/magicpet
//-------------------------------------------------------------------------
//
//
void CTaskEventSubGui::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
	if( m_vTaskEvent.size() <= 4 )
	{
		m_pUpScorl->setIsVisible( false );
		m_pDownScorl->setIsVisible( false );
		return;
	}

	CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSetIterator it = pTouches->begin();
	CCTouch* touch = (CCTouch*)(*it);

	CCPoint touchLocation = touch->locationInView( touch->view() );	
	CCPoint prevLocation = touch->previousLocationInView( touch->view() );	
	
	touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
	prevLocation = CCDirector::sharedDirector()->convertToGL( prevLocation );
	
	CCPoint diff = ccpSub(touchLocation, prevLocation);
	CCPoint currentPos = m_pGroupNode->getPosition();
	m_pGroupNode->setPosition( ccp( currentPos.x, ccpAdd(currentPos, diff).y ) );


	m_pUpScorl->setIsVisible( true );
	m_pDownScorl->setIsVisible( true );
	if( m_pGroupNode->getPosition().y <= 0 )
	{
		m_pGroupNode->setPosition( ccp( m_pGroupNode->getPosition().x, 0 ) );
		m_pUpScorl->setIsVisible( false );

	}

	if( m_pGroupNode->getPosition().y >= m_iEachSizeDis * ( m_vTaskEvent.size() - 4) )
	{
		m_pGroupNode->setPosition( ccp( m_pGroupNode->getPosition().x, m_iEachSizeDis * ( m_vTaskEvent.size() - 4) ) );
		m_pDownScorl->setIsVisible( false );

	}


}
コード例 #7
0
void RenderTextureSave::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
	CCTouch *touch = (CCTouch *)touches->anyObject();
	CCPoint start = touch->locationInView(touch->view());
	start = CCDirector::sharedDirector()->convertToGL(start);
	CCPoint end = touch->previousLocationInView(touch->view());

	// begin drawing to the render texture
	m_pTarget->begin();

	// for extra points, we'll draw this smoothly from the last position and vary the sprite's
	// scale/rotation/offset
	float distance = ccpDistance(start, end);
	if (distance > 1)
	{
		int d = (int)distance;
		for (int i = 0; i < d; i++)
		{
			float difx = end.x - start.x;
			float dify = end.y - start.y;
			float delta = (float)i / distance;
			m_pBrush->setPosition(ccp(start.x + (difx * delta), start.y + (dify * delta)));
			m_pBrush->setRotation(rand() % 360);
			float r = (float)(rand() % 50 / 50.f) + 0.25f;
			m_pBrush->setScale(r);
			/*m_pBrush->setColor(ccc3(CCRANDOM_0_1() * 127 + 128, 255, 255));*/
			// Use CCRANDOM_0_1() will cause error when loading libtests.so on android, I don't know why.
			m_pBrush->setColor(ccc3(rand() % 127 + 128, 255, 255));
			// Call visit to draw the brush, don't call draw..
			m_pBrush->visit();
		}
	}

	// finish drawing and return context back to the screen
	m_pTarget->end();
}