コード例 #1
0
GestureRecognizer* GestureRecognizer::nodeForTouch(CCSet *pTouches)
{
    CCSetIterator it;
    
    for( it = pTouches->begin(); it != pTouches->end(); ++it)
    {
        if (*it)
        {
            CCTouch *touch = (CCTouch *)*it;
            CCPoint touchLocation = touch->locationInView(touch->view());
            touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation);

            if (!m_pNode)
                break;
            
            if (m_pNode->getIsVisible() && m_pNode->getTouchEnabled())
            {
                CCPoint local = m_pNode->convertToNodeSpace(touchLocation);
                CCRect r = m_pNode->nodeRect();
                r.origin = CCPointZero;
                
                if (CCRect::CCRectContainsPoint(r, local))
                {
                    this->setTouchView(touch->view());
                    return this;
                }
            }
        }
    }
    
    return NULL;
}
コード例 #2
0
ファイル: GLayer.cpp プロジェクト: daoopp/WebGame
void GLayer::ccTouchesMoved(CCSet* pTouches, CCEvent* event)
{
	if( smpModalInterface )
	{
		GnInterfacePtr ptr = smpModalInterface;
		for( CCSetIterator it = pTouches->begin(); it != pTouches->end(); ++it )
		{
			CCTouch* touch = (CCTouch*)(*it);
			CCPoint touchPoint = touch->locationInView( touch->view() );
			ptr->PushMove( touchPoint.x, touchPoint.y );
		}
		return;
	}
	for( CCSetIterator it = pTouches->begin(); it != pTouches->end(); ++it )
	{
		CCTouch* touch = (CCTouch*)(*it);
		CCPoint touchPoint = touch->locationInView( touch->view() );
		for ( gtuint i = 0 ; i < mInterfaceChildren.GetSize(); i++ )
		{
			GnInterface* child = mInterfaceChildren.GetAt( i );
			if( touch == child->GetCurrentTouch() )
				child->PushMove( touchPoint.x, touchPoint.y );
		}
	}
}
コード例 #3
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();
}
コード例 #4
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();
	}
}
コード例 #5
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));
}
コード例 #6
0
void MainLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
    CCSetIterator it = pTouches->begin();
	CCTouch* touch = (CCTouch*)(*it);
	
	CCPoint location = touch->locationInView( touch->view() );
	CCPoint convertedLocation = CCDirector::sharedDirector()->convertToGL(location);

	CCNode* s = getChildByTag(kTagSprite);
	s->stopAllActions();
	s->runAction( CCMoveTo::actionWithDuration(1, CCPointMake(convertedLocation.x, convertedLocation.y) ) );
	float o = convertedLocation.x - s->getPosition().x;
	float a = convertedLocation.y - s->getPosition().y;
	float at = (float) CC_RADIANS_TO_DEGREES( atanf( o/a) );
	
	if( a < 0 ) 
	{
		if(  o < 0 )
			at = 180 + fabs(at);
		else
			at = 180 - fabs(at);	
	}
	
	s->runAction( CCRotateTo::actionWithDuration(1, at) );
}
コード例 #7
0
//-------------------------------------------------------------------------------
//
//
void CMiniGameCatchLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	if( m_bIsHit )
	{
		return;
	}

    CCSetIterator it = pTouches->begin();
	CCTouch* touch = (CCTouch*)(*it);
    
    CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCPoint touchLocation = touch->locationInView( touch->view() );
	touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
    
    if( touchLocation.x  < m_pPet->getPosition().x )
    {
         m_iPetActionState = MINIGAME_PET_MOVE_LEFT;
    }
    else if( touchLocation.x > m_pPet->getPosition().x )
    {
         m_iPetActionState = MINIGAME_PET_MOVE_RIGHT;
    }
     m_pPet->PlayAnimation( m_pBaseDataAnimation->m_move, -1, NULL, this, false, false);
   
    
    std::string effectpath = GetGameParticlePath();
    std::string filename = effectpath + "touchDownEffect.plist";
    CCParticleSystemQuad *pEmitter = CCParticleSystemQuad::particleWithFile( filename.c_str() );
    pEmitter->setPosition( touchLocation );
    CCPoint pos = getPosition();
    addChild( pEmitter, 100 );
  
}
コード例 #8
0
void SFCoinsGameScene::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent){
    
    if(box->isLocked())
        return;
	CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);
    CCPoint location = touch->locationInView(touch->view());
    location = CCDirector::sharedDirector()->convertToGL( location );
    
    int x = (location.x -kStartX) / kTileSize;
	int y = (location.y -kStartY) / kTileSize;
	
	if (selectedTile && selectedTile->x ==x && selectedTile->y == y)
		return;
    SFGameTile *tile = box->objectAtXAndY(x, y);
    
    if(selectedTile && selectedTile->nearTile(tile))
    {
        box->setLock(true);
        this->changeWithTileABandSel(selectedTile, tile, callfuncND_selector(SFCoinsGameScene::checkSenderandData));
        selectedTile = NULL;
    }
    else
    {
        selectedTile = tile;
        this->afterOneShineTrun(tile->sprite);
    }
}
コード例 #9
0
ファイル: MapScene.cpp プロジェクト: hustpawpaw/Cocos2dDemo
void MapScene::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);

    CCPoint m_tBeginPos = touch->locationInView( touch->view() );
    m_tBeginPos = CCDirector::sharedDirector()->convertToGL( m_tBeginPos );

    float angle = 0 ;
    CCPoint direct = rocker1->getDirection();
    if (vectorLength(direct) > 0.01f)
    {
        direct.x -= 2 * direct.x;
        direct.y -= 2 * direct.y;
        angle = atan2(direct.y, direct.x);
        if (angle >= -0.001f)
        {
            angle = 360 - 180 * (angle / PI);
        }
        else
        {
            angle = (-1)  * 180 * (angle / PI);
        }

        if (fabs(player->pAngle - angle) > 3)
        {

            player->getsprite()->setRotation(angle);
            player->pAngle = angle;

        }

    }
}
コード例 #10
0
void RenderTextureTest::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
#if CC_ENABLE_CACHE_TEXTTURE_DATA

	CCSetIterator it;
	CCTouch* touch;

	for( it = touches->begin(); it != touches->end(); it++) 
	{
		touch = (CCTouch*)(*it);

		if(!touch)
			break;

		CCPoint location = touch->locationInView(touch->view());

		location = CCDirector::sharedDirector()->convertToGL(location);

		m_brush->setPosition(location);
		m_brush->setRotation( rand()%360 );
	}

	m_target->begin();
	m_brush->visit();
	m_target->end(true);
#endif
}
コード例 #11
0
void TestController::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);

    CCPoint touchLocation = touch->locationInView( touch->view() );	
    touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
    float nMoveY = touchLocation.y - m_tBeginPos.y;

    CCPoint curPos  = m_pItemMenu->getPosition();
    CCPoint nextPos = ccp(curPos.x, curPos.y + nMoveY);
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    if (nextPos.y < 0.0f)
    {
        m_pItemMenu->setPosition(CCPointZero);
        return;
    }

    if (nextPos.y > ((TESTS_COUNT + 1)* LINE_SPACE - winSize.height))
    {
        m_pItemMenu->setPosition(ccp(0, ((TESTS_COUNT + 1)* LINE_SPACE - winSize.height)));
        return;
    }

    m_pItemMenu->setPosition(nextPos);
    m_tBeginPos = touchLocation;
    s_tCurPos   = nextPos;
}
コード例 #12
0
void TestController::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
    CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);

    m_tBeginPos = touch->locationInView( touch->view() );	
    m_tBeginPos = CCDirector::sharedDirector()->convertToGL( m_tBeginPos );
}
コード例 #13
0
void LCCrossMatchGame::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	// 멀티터치 금지
	if (singleTouch != NULL) 
	{
		return;
	}
	
	CCTouch *touch = (CCTouch*)pTouches->anyObject();
	singleTouch = touch;
	
	prevTouchLocation = touch->locationInView( touch->view() );

	moveAmount = 0;
	
	m_pTouchedDotSprite = NULL;
	for (int i=0; i<m_pDotSprites->count(); i++) {
		CCSprite *dotSprite = (CCSprite *)m_pDotSprites->objectAtIndex(i);
		if (LCUtil::isTouchInside(dotSprite, pTouches)) {
			m_pTouchedDotSprite = dotSprite;
			break;
		}
	}
	
	// image touch 및 text label touch 구역 추가 on 11.10.17
	if (!m_pTouchedDotSprite) {
		for (int i=0; i<m_pImageArray->count(); i++) {
			CCSprite *imageSprite = (CCSprite *)m_pImageArray->objectAtIndex(i);
			if (LCUtil::isTouchInside(imageSprite, pTouches)) {
				// dotArray에 이미지 부분부터 추가되므로
				for (int i=0; i<m_pDotSprites->count(); i++) {
					CCSprite *dotSprite = (CCSprite *)m_pDotSprites->objectAtIndex(i);
					if (dotSprite->getTag() == imageSprite->getTag()) {
						m_pTouchedDotSprite = dotSprite;
						break;
					}
				}
			}
		}
	}
	
	if (!m_pTouchedDotSprite) {
		for (int i=0; i<m_pTextArray->count(); i++) {
			CCLabelTTF *textLabel = (CCLabelTTF*)m_pTextArray->objectAtIndex(i);
			if (LCUtil::isTouchInside(textLabel, pTouches)) {
				// dotArray에 이미지 부분부터 추가되므로 뒤에서부터 탐색
				for (int i=m_pDotSprites->count()-1; i>=0; i--) {
					CCSprite *dotSprite = (CCSprite *)m_pDotSprites->objectAtIndex(i);
					if (dotSprite->getTag() == textLabel->getTag()) {
						m_pTouchedDotSprite = dotSprite;
						break;
					}
				}
			}
		}
	}
}
コード例 #14
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 );

	}


}
コード例 #15
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 );
	}


}
コード例 #16
0
void TestController::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
    stopAllActions();
    CCDelayTime* delaytime = CCDelayTime::actionWithDuration(0.2);
    delaytime->setTag(99);
    this->runAction(delaytime);
    CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);
    m_tBeginPos = touch->locationInView(touch->view());
}
コード例 #17
0
void HelloWorld::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
    if (_mouseJoint == NULL) return;
    
    CCTouch *myTouch = (CCTouch *)touches->anyObject();
    CCPoint location = myTouch->locationInView(myTouch->view());
    location = CCDirector::sharedDirector()->convertToGL(location);
    b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);

    _mouseJoint->SetTarget(locationWorld);
}
コード例 #18
0
void LCWordCloudLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS )	
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID )	
	CCTouch *touch = (CCTouch*)pTouches->anyObject();
	initialTouchLocation = touch->locationInView( touch->view() );
#endif
	
	m_bIsMoved = false;
}
コード例 #19
0
ファイル: HelloWorldScene.cpp プロジェクト: Menki/Breakout
void HelloWorld::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
    if (mouseJoint == NULL) return;
    
    CCTouch *myTouch = (CCTouch *) pTouches->anyObject();
    CCPoint location = myTouch->locationInView(myTouch->view());
    location = CCDirector::sharedDirector()->convertToGL(location);
    b2Vec2 locationWorld = b2Vec2(location.x/ptmRatio, location.y/ptmRatio);

    mouseJoint->SetTarget(locationWorld);
}
コード例 #20
0
CCTouch* CCEGLView::findTouch(int id) 
{
    CCSetIterator iter;
	for (iter = m_pSet->begin(); iter != m_pSet->end(); ++iter)
	{
        CCTouch *touch = (CCTouch*)*iter;
                
		if(touch->view() == id)
            return touch;
	}
    
    return NULL;
}
コード例 #21
0
// cpp with cocos2d-x
void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
	// Choose one of the touches to work with
	CCTouch* touch = (CCTouch*)( touches->anyObject() );
	CCPoint location = touch->locationInView(touch->view());

	location = CCDirector::sharedDirector()->convertToGL(location);

	// Set up initial location of projectile
	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	CCSprite *projectile = CCSprite::spriteWithFile("Projectile.png", 
		CCRectMake(0, 0, 20, 20));
	projectile->setPosition( ccp(20, winSize.height/2) );

	// Determinie offset of location to projectile
	float offX = location.x - projectile->getPosition().x;
	float offY = location.y - projectile->getPosition().y;

	// Bail out if we are shooting down or backwards
	if (offX <= 0) return;

	// Ok to add now - we've double checked position
	this->addChild(projectile);

	// Determine where we wish to shoot the projectile to
	float realX = winSize.width + (projectile->getContentSize().width/2);
	float ratio = offY / offX;
	float realY = (realX * ratio) + projectile->getPosition().y;
	CCPoint realDest = ccp(realX, realY);

	// Determine the length of how far we're shooting
	float offRealX = realX - projectile->getPosition().x;
	float offRealY = realY - projectile->getPosition().y;
	float length = sqrtf((offRealX * offRealX) + (offRealY*offRealY));
	float velocity = 480/1; // 480pixels/1sec
	float realMoveDuration = length/velocity;

	// Move projectile to actual endpoint
	projectile->runAction( CCSequence::actions(
		CCMoveTo::actionWithDuration(realMoveDuration, realDest),
		CCCallFuncN::actionWithTarget(this, 

		callfuncN_selector(HelloWorld::spriteMoveFinished)), 
		NULL) );

	// Add to projectiles array
	projectile->setTag(2);
	_projectiles->addObject(projectile);

	CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("pew-pew-lei.wav");
}
コード例 #22
0
void HelloWorld::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
        CCLOG("touch moved");
    if(m_pMouseJoin == NULL)
    {
        return;
    }
    
    CCTouch * touch = (CCTouch*)pTouches->anyObject();
    CCPoint location = touch->locationInView(touch->view());
    location = CCDirector::sharedDirector()->convertToGL(location);
    b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO,location.y/PTM_RATIO);
    
    m_pMouseJoin->SetTarget(locationWorld);
}
コード例 #23
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();
}
コード例 #24
0
ファイル: MapScene.cpp プロジェクト: hustpawpaw/Cocos2dDemo
void MapScene::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
    //if(stepindex == -5){
    stepindex == -1;
    CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);
    CCPoint m_tBeginPos = touch->locationInView( touch->view() );
    m_tBeginPos = CCDirector::sharedDirector()->convertToGL( m_tBeginPos );
    if ( m_tBeginPos.x > 500 && m_tBeginPos.y < 180 )
    {
        unschedule(schedule_selector(MapScene::resettouch));
    }
    // stepindex = -1;
    //}
}
コード例 #25
0
void LayerGradient::ccTouchesMoved(CCSet * touches, CCEvent *event)
{
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSetIterator it = touches->begin();
    CCTouch* touch = (CCTouch*)(*it);
    CCPoint start = touch->locationInView(touch->view());	
    start = CCDirector::sharedDirector()->convertToGL(start);

    CCPoint diff = ccpSub( ccp(s.width/2,s.height/2), start);	
    diff = ccpNormalize(diff);

    CCLayerGradient *gradient = (CCLayerGradient*) getChildByTag(1);
    gradient->setVector(diff);
}
コード例 #26
0
bool GestureRecognizer::containsTouch(cocos2d::CCSet *pTouches)
{
    CCSetIterator it;
    
    for( it = pTouches->begin(); it != pTouches->end(); ++it)
    {
        if (*it)
        {
            CCTouch *touch = (CCTouch *)*it;
            if (m_nTouchView == touch->view())
                return true;            
        }
    }
    
    return false;
}
コード例 #27
0
ファイル: DirectorTest.cpp プロジェクト: Bahamut/cocos2d-x
void Director1::ccTouchesEnded(CCSet * touches, CCEvent* event)
{
    CCSetIterator it;
    CCTouch* touch;

    for( it = touches->begin(); it != touches->end(); it++) 
    {
        touch = (CCTouch*)(*it);

        if(!touch)
            break;
		CCPoint a = touch->locationInView(touch->view());

        CCDirector *director = CCDirector::sharedDirector();
		CCPoint b = director->convertToUI(director->convertToGL(a));
		CCLog("(%d,%d) == (%d,%d)", (int) a.x, (int)a.y, (int)b.x, (int)b.y );
	}
}
コード例 #28
0
void HelloWorld::ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent* event)
{
    if (_mouseJoint != NULL) return;
    
    CCTouch *myTouch = (CCTouch *)touches->anyObject();
    CCPoint location = myTouch->locationInView(myTouch->view());
    location = CCDirector::sharedDirector()->convertToGL(location);
    b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
    
    b2MouseJointDef md;
    md.bodyA = _groundBody;
    md.bodyB = _paddleBody;
    md.target = locationWorld;
    md.collideConnected = true;
    md.maxForce = 1000.0f * _paddleBody->GetMass();
    
    _mouseJoint = (b2MouseJoint *)_world->CreateJoint(&md);
    _paddleBody->SetAwake(true);
}
コード例 #29
0
void TestController::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
    CCAction* delaytime = CCActionManager::sharedManager()->getActionByTag(99,this);
    if(delaytime != NULL)
        if(delaytime->isDone() == false)
        {
            CCSetIterator it = pTouches->begin();
            CCTouch* touch = (CCTouch*)(*it);
            CCPoint p1 =	m_tBeginPos;
            CCPoint p2 =	touch->locationInView(touch->view());
            float x = m_pItmeMenu->getPosition().x + (p2.x - p1.x) * 5;
            if(x>= 0)
                x = 0;
            else if(x <= -m_pItmeMenu->getContentSize().width)
                x = -m_pItmeMenu->getContentSize().width;
            CCMoveTo* move = CCMoveTo::actionWithDuration(1,CCPointMake(x,0));
            CCActionInterval* ease = CCEaseOut::actionWithAction(move,3.0);
            m_pItmeMenu->runAction(ease);
        }
}
コード例 #30
0
ファイル: Box2dTest.cpp プロジェクト: BigHand/cocos2d-x
void Box2DTestLayer::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
	//Add a new body/atlas sprite at the touched location
	CCSetIterator it;
	CCTouch* touch;

	for( it = touches->begin(); it != touches->end(); it++) 
	{
		touch = (CCTouch*)(*it);

		if(!touch)
			break;

		CCPoint location = touch->locationInView(touch->view());
		
		location = CCDirector::sharedDirector()->convertToGL(location);
	
		addNewSpriteWithCoords( location );
	}
}