Beispiel #1
0
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 );
		}
	}
}
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);
    }
}
Beispiel #3
0
void CocosDenshionTest::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);

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

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

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

    m_pItmeMenu->setPosition(nextPos);
    m_tBeginPos = touchLocation;
}
Beispiel #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();
	}
}
//-------------------------------------------------------------------------------
//
//
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 );
  
}
Beispiel #6
0
// *************************************************************************************************
// 觸控﹣按下
// *************************************************************************************************
void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
    CCLog("%s", __PRETTY_FUNCTION__);
    if(this->getIsKeypadEnabled())
    {
        CCSetIterator it = pTouches->begin();
        CCTouch *touch = (CCTouch*)(*it);
        
        // 获取点在视图中的坐标(左上角为原点)
        CCPoint touchLocation = touch->locationInView();
        // 把点的坐标转换成OpenGL坐标(左下角为原点)
        touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation);
        
        for(int a = 0; a < InAppPurchase.Num; a++)
        {
            // 把OpenGL的坐標轉換成CCSprite的坐標
            CCPoint local = spriteStoreItems[a]->convertToNodeSpace(touchLocation);
            CCLOG("local x= %f y = %f",local.x,local.y);
            
            CCRect rect = spriteStoreItems[a]->getTextureRect();
            rect.origin = CCPointZero;
            
            if(CCRect::CCRectContainsPoint(rect, local))
            {
                layerIap->BuyItem(a); // 購買項目
                break;
            }
        }
    }
}
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
}
Beispiel #8
0
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;

        }

    }
}
Beispiel #9
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();
}
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;
}
Beispiel #11
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) );
}
Beispiel #12
0
void MapScene::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);

    CCPoint m_tBeginPos = touch->locationInView();	
    m_tBeginPos = CCDirector::sharedDirector()->convertToGL( m_tBeginPos );
	CCPoint playerpoint = gameplayer->getPosition();
	CCSize palyersize = gameplayer->getContentSize();
    CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
	CCPoint mappoint = map->getPosition();
    //根据触摸点的位置判断人物移动方向
	if(m_tBeginPos.x < playerpoint.x - palyersize.width / 2 + mappoint.x){
	   hmove = -1;//左移
	}else if(m_tBeginPos.x > playerpoint.x + palyersize.width / 2 + mappoint.x){
	   hmove = 1;//右移
	}else{
	   hmove = 0;
	}
	if(m_tBeginPos.y > playerpoint.y + palyersize.height + mappoint.y){
	   vmove = 6;//上跳
	}else{
	   vmove = 0;
	}
}
void HelloWorld::ccTouchesBegan(CCSet *touches, CCEvent *pEvent)
{
    CCSetIterator it;
    CCTouch* touch;
    
    for( it = touches->begin(); it != touches->end(); it++) 
    {
        touch = (CCTouch*)(*it);
        
        if(!touch)
            break;        
        
        CCPoint winPos = touch->locationInView();
        winPos = CCDirector::sharedDirector()->convertToGL(winPos);
        
        //CCLog("x: %f   y: %f", winPos.x, winPos.y);
        
        CCSetIterator it;
        Box* box;
        
        for( it = set->begin(); it != set->end(); it++) 
        {
            box = (Box*)(*it);
            
            if(winPos.x > box->getTopLeft().x && winPos.x < box->getBottomRight().x && winPos.y > box->getBottomRight().y && winPos.y < box->getTopLeft().y)
            {
                box->setSelectedValue(true);   
            }   
        }
    }
}
void BugsTestMainLayer::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 );
}
void HelloWorld::ccTouchesBegan(CCSet* touches, CCEvent* event) {
	CCTouch* touch = (CCTouch*) (touches->anyObject());
	CCPoint location = touch->locationInView();

	//CCLog("++++++++begin befor  x:%f, y:%f", location.x, location.y);
	startLocation = CCDirector::sharedDirector()->convertToGL(location);
	//CCLog("++++++++begin after  x:%f, y:%f", startLocation.x, startLocation.y);
}
Beispiel #16
0
void CocosDenshionTest::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
    CCSetIterator it = pTouches->begin();
    CCTouch* touch = (CCTouch*)(*it);

    m_tBeginPos = touch->locationInView();    
    m_tBeginPos = CCDirector::sharedDirector()->convertToGL( m_tBeginPos );
}
void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event) {
	if(state == INIT) {
		CCLog("state:INIT");
	} else if(state == START) {
		CCLog("state:START");
	}

	CCTouch* touch = (CCTouch*) (touches->anyObject());
	CCPoint location = touch->locationInView();

	//CCLog("++++++++end befor  x:%f, y:%f", location.x, location.y);
	location = CCDirector::sharedDirector()->convertToGL(location);
	//CCLog("++++++++end after  x:%f, y:%f", location.x, location.y);

	if (playerMain->containPoint(&location) && state == INIT) {
//	if (startLocation.x > playerMain->boardPos.x && startLocation.x
//			< playerMain->boardPos.x + 10 * playerMain->lenPerTile
//			&& startLocation.y > playerMain->boardPos.y && startLocation.y
//			< playerMain->boardPos.y + 10 * playerMain->lenPerTile
	//&& location.x > playerMain->boardPos.x
	//&& location.x < playerMain->boardPos.x + 10*playerMain->lenPerTile
	//&& location.y > playerMain->boardPos.y
	//&& location.y < playerMain->boardPos.y + 10*playerMain->lenPerTile
//	) {
		CCLog("in board");
		Plane* plane = playerMain->getPlane(startLocation);
		if (plane != NULL) {
			//CCLog("not null");
			//如果是旋转
			if (startLocation.x - location.x > playerMain->lenPerTile
					&& startLocation.y - location.y > playerMain->lenPerTile) {
				CCLog("***********rotate");
				//TODO 有些空间比较小的地方,旋转用户体验不好。向下或者向左移动后可以旋转。
				playerMain->rotate(plane);
			} else if (startLocation.x - location.x > playerMain->lenPerTile
					&& fabs(startLocation.y - location.y)
							< playerMain->lenPerTile) { //左移
				playerMain->move(plane, -1, 0);
			} else if (location.x - startLocation.x > playerMain->lenPerTile
					&& fabs(startLocation.y - location.y)
							< playerMain->lenPerTile) { //右移
				CCLog("***********right");
				CCLog("***********plane:%f", plane->pos.x);
				playerMain->move(plane, 1, 0);
			} else if (fabs(location.x - startLocation.x)
					< playerMain->lenPerTile && location.y - startLocation.y
					> playerMain->lenPerTile) { //上移
				playerMain->move(plane, 0, 1);
			} else if (fabs(location.x - startLocation.x)
					< playerMain->lenPerTile && startLocation.y - location.y
					> playerMain->lenPerTile) { //下移
				playerMain->move(plane, 0, -1);
			}
		}
	} else if(playerSubordinate->containPoint(&location) && state == START) {
		CCLog("attack");
	}
}
Beispiel #18
0
void Stage::ccTouchesBegan( cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent )
{
	if(totalBall < 1){
		return;
	};
	CCSetIterator it;
	CCTouch* touch;

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

		if(!touch)
			break;

		CCPoint location = touch->locationInView();

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

		/////
		b2BodyDef bodyDef;
		bodyDef.type = b2_dynamicBody;
		CCSize s = CCDirector::sharedDirector()->getWinSize();
		location.x = s.width * 0.6;
		location.y = s.height * 0.85;
		bodyDef.position.Set(location.x/PTM_RATIO, location.y/PTM_RATIO);

		body = world->CreateBody(&bodyDef);

		// Define another box shape for our dynamic body.

		b2CircleShape dynamicCircle;
		float rtmp = BALL_R ;//+ 10 * CCRANDOM_MINUS1_1();
		dynamicCircle.m_radius = rtmp / PTM_RATIO;
		// Define the dynamic body fixture.
		b2FixtureDef fixtureDef;
		fixtureDef.shape = &dynamicCircle;    
		fixtureDef.density = 3.0f;
		fixtureDef.friction = 0.8f;
		fixtureDef.restitution = 0.5f;
		body->CreateFixture(&fixtureDef);
		body->ResetMassData();

		
		float tmp = CCRANDOM_0_1();
		
		Ball* pBall = new Ball();
		pBall->m_r = rtmp;
		pBall->m_pBody = body;
		pBall->pos.x = body->GetPosition().x * PTM_RATIO;
		pBall->pos.y = body->GetPosition().y * PTM_RATIO;
		ball_vec_.push_back(pBall);
		//CCLog("ball info: color=%d, x=%f, y=%f",pBall->m_color, pBall->pos.x, pBall->pos.y );
		totalBall--;


	}
}
void HSJoystick::ccTouchesMoved( CCSet *pTouches, CCEvent *pEvent )
{
    if(isPressed) {
        CCTouch *touch = (CCTouch*)pTouches->anyObject();
        CCPoint point = touch->locationInView();
        point = convertCoordinate(point);
        this->updateVelocity(point);
    }
}
Beispiel #20
0
void GameLayer::ccTouchesEnded(cocos2d::CCSet* pTouches, cocos2d::CCEvent *pEvent)
{
	CCTouch* touch = (CCTouch*)pTouches->anyObject();
	// 获得触摸点坐标
	CCPoint location = touch->locationInView();
	CCPoint convertedLocation = CCDirector::sharedDirector()->convertToGL(location);
	// 让飞船在1秒钟内移动过去
	flight->runAction(CCMoveTo::actionWithDuration(1.0f, ccp(convertedLocation.x, convertedLocation.y)));
}
Beispiel #21
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;
					}
				}
			}
		}
	}
}
void MotionStreakTest2::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
    CCSetIterator it = touches->begin();
    CCTouch* touch = (CCTouch*)(*it);

    CCPoint touchLocation = touch->locationInView();    
    touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
    
    m_streak->setPosition( touchLocation );
}
void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
	CCTouch *touch = (CCTouch *)pTouches->anyObject();
	CCPoint location = touch->locationInView();
	location = CCDirector::sharedDirector()->convertToGL(location);

	CCSprite *sprite = CCSprite::create("moles_icon.png");
	sprite->setPosition(location);
	this->addChild(sprite, 1);
}
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());
}
Beispiel #25
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;
}
Beispiel #26
0
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);
}
void HSJoystick::ccTouchesBegan( CCSet *pTouches, CCEvent *pEvent )
{
    CCTouch *touch = (CCTouch*)pTouches->anyObject();
    CCPoint point = touch->locationInView();
    point = convertCoordinate(point);

    if(isPointInCircle(point,kCenter,this->radius)) {
        isPressed = true;
        this->updateVelocity(point);
    }
}
Beispiel #28
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);
}
Beispiel #29
0
void MutiTouchTestLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    CCSetIterator iter = pTouches->begin();
    for (; iter != pTouches->end(); iter++)
    {
        CCTouch* pTouch = (CCTouch*)(*iter);
        TouchPoint* pTP = (TouchPoint*)s_dic.objectForKey(pTouch->getID());
        CCPoint location = pTouch->locationInView();
        location = CCDirector::sharedDirector()->convertToGL(location);
        pTP->setTouchPos(location);
    }
}
void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
	// Choose one of the touches to work with
	CCTouch* touch = (CCTouch*)( touches->anyObject() );
	CCPoint location = touch->locationInView();
	location = CCDirector::sharedDirector()->convertToGL(location);

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

	// Determinie offset of location to projectile
	int offX = location.x - projectile->getPosition().x;
	int 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
	int realX = winSize.width
		+ (projectile->getContentSize().width/2);
	float ratio = (float)offY / (float)offX;
	int realY = (realX * ratio) + projectile->getPosition().y;
	CCPoint realDest = ccp(realX, realY);

	// Determine the length of how far we're shooting
	int offRealX = realX - projectile->getPosition().x;
	int 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::create(
		CCMoveTo::create(realMoveDuration, realDest),
		CCCallFuncN::create(this, 

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

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

	CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("pew-pew-lei.wav"); 
}