Example #1
0
void StartScene::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
	CCTouch* touch = (CCTouch*)(* pTouches->begin());
    CCPoint pos = touch->getLocation();
	
	/**
	 * 处理窗口
	 */
	if (mainUI->touchDown(pos.x,pos.y)) return;
	
}
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->getLocation();
        pTP->setTouchPos(location);
    }
}
void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent){
    
    CCTouch* t = (CCTouch*)pTouches->anyObject();
    
    touchStart = t->getLocation();
    if(img->boundingBox().containsPoint(touchStart)){
        imgStart = img->getPosition();
        
        dragenabled = true;
    }
}
void HelloWorld::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent){
    CCTouch* t = (CCTouch*)pTouches->anyObject();
    
    if (dragenabled) {
        img->setPosition(t->getLocation()-touchStart+imgStart);
        
        if (img->boundingBox().intersectsRect(img1->boundingBox())) {
            CCLog("intersect\n");
        }
    }
}
Example #5
0
void StartScene::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
	CCTouch* touch = (CCTouch*)(* pTouches->begin());
    CCPoint pos = touch->getLocation();
	
	/**
	 * 处理窗口
	 */
	if (window->touchDown(pos.x,pos.y)) return;
	MapManager::getMe().doTouch(UIBase::TOUCH_DOWN,pos);
	
}
Example #6
0
void PageScrollView::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
	CCTouch *touch = (CCTouch *)pTouches->anyObject();
	CCPoint currentPoint = (CCPoint)touch->getLocation();
	CCPoint prePoint = (CCPoint)touch->getPreviousLocation();

	if(isTouchMoving){
		v = currentPoint.x - prePoint.x;
		content->setPositionX(content->getPositionX() + v);
	}
	
}
Example #7
0
void ChessBoard::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
	CCPoint pos;
	CCSetIterator i;
	CCTouch* touch;
	ChessBall* sprite;

	_cancelling = true;

	if (_roundEnd)
	{
		return;
	}
	int count = _chessArray->count();

	for (i = pTouches->begin(); i != pTouches->end(); i++)
	{
		touch = (CCTouch*)(*i);
		if (touch != NULL)
		{
			pos = touch->getLocation();
			_pickedChess->setPositionX(pos.x);
			_pickedChess->setPositionY(pos.y + _chessYOffset);

			for (int j = 0; j < count; j++)
			{
				sprite = (ChessBall*)_chessArray->objectAtIndex(j);
				if (sprite->boundingBox().containsPoint(pos))
				{
				//	sprite->setOpacity(128);
					if (_activeCell->ball != NULL && _activeCell->ball != sprite)
					{
						CCMoveTo * move = CCMoveTo::create(0.1f, _activeCell->ball->getPosition());
						CCCallFuncND * end = CCCallFuncND::create(this, callfuncND_selector(ChessBoard::chessMoveEnd), _activeCell->ball);
						CCAction * action = CCSequence::create(move, end,NULL);
						_moveChess->setVisible(true);
						_moveChess->setChessProperty(sprite->getChessProperty());
						_moveChess->setPosition(sprite->getPosition());
						_moveChess->runAction(action);

						_activeCell->ball->setOpacity(0);
						_activeCell->ball->setChessProperty(sprite->getChessProperty());

						_activeCell->ball = sprite;
						_activeCell->ball->setOpacity(128);
						_activeCell->ball->setChessProperty(_pickedChess->getChessProperty());
					}
				}
			}
		}
	}
	
}
void BaseContentWrapLayer::ccTouchesMoved (CCSet *pTouches, CCEvent *pEvent)
{
	if (!mBaseScene->getCollisionEnable())
	{
		return;
	}

	if (mFixedScaling)
	{
		return;
	}
	
	CCTouch* touch = (CCTouch*)(*(pTouches->begin()));
    if(touch->getID() != 0 || pTouches->count() > 1)
        return;
    
	CCPoint currentPos = touch->getLocation();
	mVCalculate->addTouchMoveRecord(currentPos);

	float x_offset = currentPos.x - mLastTouchPos.x;
	float y_offset = currentPos.y - mLastTouchPos.y;

	setPositionX(getPositionX() + x_offset);
	setPositionY(getPositionY() + y_offset);

	mLastTouchPos = currentPos;

	float min_x;
	float min_y;
	float max_x;
	float max_y;
	getBoarderPos(min_x,min_y,max_x,max_y);

	if (getPositionX() < min_x)
	{
		setPositionX(min_x);
	}
	if (getPositionX() > max_x)
	{
		setPositionX(max_x);
	}

	if (getPositionY() < min_y)
	{
		setPositionY(min_y);
	}
	if (getPositionY() > max_y)
	{
		setPositionY(max_y);
	}
	

}
void GameLayer::ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent* event) {
    
    if (_gameState != kGameStatePlay) return;
    
    CCTouch *touch = (CCTouch *) touches->anyObject();
    
    if (touch) {
	    
	    CCPoint tap = touch->getLocation();
        _drawLayer->setStartPoint(tap);
    }
}
Example #10
0
// cpp with cocos2d-x
void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
	//jni_test();

	// Choose one of the touches to work with
	CCTouch* touch = (CCTouch*)( touches->anyObject() );
	CCPoint location = touch->getLocation();
    
	//CCLog("++++++++after  x:%f, y:%f", location.x, location.y);

	// Set up initial location of projectile
	CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
	CCSprite *projectile = CCSprite::create("Projectile.png", CCRectMake(0, 0, 20, 20));
	projectile->setPosition( ccp(origin.x+20, origin.y+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 = origin.x+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::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");
}
Example #11
0
void GameScene::ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event)
{
    CCTouch* touch = (CCTouch*)(touches->anyObject());
    CCPoint pt = touch->getLocation();
    CCPoint d = ccpSub(pt, mClickPoint);
    if (fabs(d.x) < 2.0f && fabs(d.y) < 2.0f) {
        onClick(pt);
    }

    lastScale = 0.0f;
    mScaleDistance = 0.0f;
    pDebug->setString("END");
}
Example #12
0
void MainMenuLayer::ccTouchesEnded(CCSet* touches, CCEvent* event) {
	CCTouch* touch = (CCTouch*)( touches->anyObject() );
	CCPoint location = touch->getLocation();

	if (!m_sound->boundingBox().containsPoint(location))
		return;
	bool mute = !Config::instance()->mute();
	Config::instance()->setMute(mute);
	if (mute)
		m_sound->setDisplayFrame(m_muteFrame);
	else
		m_sound->setDisplayFrame(m_soundFrame);
}
Example #13
0
void CMenuLayer::ccTouchesBegan(CCSet* pTouches, CCEvent* event)
{
	if( _mGameStart )
		return;
	
	for( CCSetIterator it = pTouches->begin(); it != pTouches->end(); ++it )
	{
		CCTouch* touch = (CCTouch*)(*it);
		CCPoint touchPoint = touch->getLocation();

		_mOldTouch = touchPoint;
	}
}
Example #14
0
void GameScene::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    if (pTouches->count() == 2) {

        CCSetIterator it1 = pTouches->begin();
        CCSetIterator it2 = it1;
        it2++;
        CCPoint pt1 = ((CCTouch*)(*it1))->getLocation();
        CCPoint pt2 = ((CCTouch*)(*it2))->getLocation();
        float dist = sqrt((pt1.x - pt2.x) * (pt1.x - pt2.x) + (pt1.y - pt2.y) * (pt1.y - pt2.y));

        if (lastScale < 1.0f || mScaleDistance == 0.0f) {
            lastScale = this->getScale();
            mScaleDistance = dist;
        }

        float scale =  lastScale * (dist / mScaleDistance);

        { 
            char    temp[4096];
            snprintf(temp, sizeof(temp), "%f/%f/%f", dist, mScaleDistance, scale);
            pDebug->setString(temp);
        }

        if (scale < 1.0f)
            scale = 1.0f;
        if (scale > 2.0f)
            scale = 2.0f;

        lastScale = scale;
        mScaleDistance = dist;

        this->setScale(scale);
    } else {
        CCTouch* touch = (CCTouch*)(pTouches->anyObject());
        singleTouchDragging(mDragStartPoint, touch->getLocation());
        mDragStartPoint = touch->getLocation();
    }
}
Example #15
0
void RoundPageScrollView::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
	CCTouch *touch = (CCTouch *)pTouches->anyObject();
    
    CCPoint curLocalPoint = convertToNodeSpace((CCPoint)touch->getLocation());
    CCPoint preLocalPoint = convertToNodeSpace((CCPoint)touch->getPreviousLocation());
    
	if(isTouchMoving){
        v = atan(curLocalPoint.x/radius) - atan(preLocalPoint.x/radius);
        w += v;
	}
	
}
Example #16
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->getLocation();

	CCLog("++++++++after  x:%f, y:%f", location.x, location.y);

	// Set up initial location of projectile
	CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

}
/// Process touching and moving to add/remove walls 
KDvoid Ch7_GridPathfinding::ccTouchesBegan ( CCSet* pTouches, CCEvent* pEvent )
{
	CCTouch*	pTouch = (CCTouch*) pTouches->anyObject ( );
    CCPoint		tPoint = pTouch->getLocation ( );

	KDint		x = (KDint) ( ( tPoint.x - m_pGridNode->getPosition ( ).x ) / m_fNodeSpace );
	KDint		y = (KDint) ( ( tPoint.y - m_pGridNode->getPosition ( ).y ) / m_fNodeSpace );

	CCPoint		tTouchedNode = ccp ( x, y );
	
	m_bTouchedNodeIsNew = KD_TRUE;
	m_tTouchedNode = tTouchedNode;
}
Example #18
0
void CRankingModeLayer::ccTouchesBegan(CCSet* pTouches, CCEvent* event)
{
	for( CCSetIterator it = pTouches->begin(); it != pTouches->end(); ++it )
	{
		CCTouch* touch = (CCTouch*)(*it);
		CCPoint touchPoint = touch->getLocation();

		_mOldTouch = touchPoint;

		_mSwipeSprite->setVisible(false);
		_mSwipeOppSprite->setVisible(false);
	}
}
KDvoid SuperMarioClick::ccTouchesMoved ( CCSet* pTouches, CCEvent* pEvent )
{
	if ( m_pMouseJoint == KD_NULL )
	{
		return;
	}

	CCTouch*	pTouch = (CCTouch*) pTouches->anyObject ( );
	CCPoint		tLocation = pTouch->getLocation ( );
	b2Vec2		tLocationWorld = b2Vec2 ( tLocation.x / PTM_RATIO, tLocation.y / PTM_RATIO );

	m_pMouseJoint->SetTarget ( tLocationWorld );
}
void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent){
	CCLOG("win x:%f,Ground x:%f,mfac:%f,index=%d ",this->mScreenSize.width,
		m_pGroundVec[m_ilastground]->boundingBox().getMaxX(),mfac,m_ilastground);
	static int flag;       
	CCTouch *pTouch = (CCTouch*)pTouches->anyObject();  
	CCPoint click2 = pTouch->getLocation();  
	CCLog("ccTouchesBegan,%d,%f,%f",++flag,click2.x,click2.y); 
	if(this->m_istatus!=RUNNING){
		if(m_istatus==GETREADY)
		{
			this->startGame(0);
		}
		CCPoint touchPoint = pTouch->getLocationInView();
		touchPoint = CCDirector::sharedDirector()->convertToGL(touchPoint);
		CCRect rect = m_pStart->boundingBox();
		//在判断你点击的这个点touchPoint 是否在图片按钮矩形里面rect ;
		if(rect.containsPoint(touchPoint))
		{


			if(m_istatus==GAMEOVER && m_pStart->isVisible())
			{
				//this->goReady();
				//m_istatus=GETREADY;
				//schedule(schedule_selector(HelloWorld::ScoreSchedule),0.05);

				CCScene *pScene = HelloWorld::scene();
				CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1,pScene));

				return;
			}
		}
		//为true就进来,说明点中在图片按钮矩形里面
		//CCScene* scen = HelloWorld::scene();
		//CCDirector::sharedDirector()->replaceScene(scen);

	}
	if(m_istatus!=RUNNING)
	{
		return;
	}
//	EFFECT_PLAY(true,MUSIC_WING);
	//MUSIC_PLAY(MUSIC_JUMP);
	//播放子弹射出去的声音
	//CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(MUSIC_JUMP);
	mBird->getB2Body()->SetLinearVelocity(b2Vec2(0.0f, gUpVelocity/mfac));
	mBird->setRotation(25);
	myangle=25;
	iFlyKeep=0;

}
Example #21
0
void LayerGradient::ccTouchesMoved(CCSet * touches, CCEvent *event)
{
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSetIterator it = touches->begin();
    CCTouch* touch = (CCTouch*)(*it);
    CCPoint start = touch->getLocation();    

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

    CCLayerGradient *gradient = (CCLayerGradient*) getChildByTag(1);
    gradient->setVector(diff);
}
Example #22
0
void DaFeiJi::ccTouchesMoved(CCSet * touches, CCEvent *event)
{
	if( _state == GAME_STATE::PLAY ) 
	{
		CCSetIterator it = touches->begin();
		CCTouch* touch = (CCTouch*)(*it);
		CCPoint start = touch->getLocation();    
		CCPoint delta = touch->getDelta();
		CCPoint curPos = _ship->getPosition();
		curPos= ccpAdd( curPos, delta );
		curPos = ccpClamp(curPos, CCPoint(), CCPoint(_winSize.width, _winSize.height) );
		_ship->setPosition( curPos );
	}
}
Example #23
0
void HelloWorld::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) {
	CCSetIterator it = pTouches->begin();
	CCTouch* touch = (CCTouch*) (*it);

	CCPoint location = touch->getLocation();

	PUD pud = { gameNet.getPlayer()->pud.session, GAME_EVENT_MOVE,
				0, 0, 0, 10, 10,
				location.x, location.y };

//	CCLog("player move pud:  session=%d,type=%d,x1=%d,y1=%d,x2=%d,y2=%d",
//			pud.session,pud.type,pud.x1,pud.y1,pud.x2,pud.y2);
	gameNet.sendMoveData(pud);
}
void HelpLayer::ccTouchesMoved(cocos2d::CCSet* touches, cocos2d::CCEvent* event) {
    
    if (_gameState != kGameStatePlay || !_running) return;
    
    CCTouch *touch = (CCTouch *) touches->anyObject();
    
    
    if (touch) {
	    
	    CCPoint tap = touch->getLocation();
        
        _drawLayer->setTouchPoint(tap);
    }
}
Example #25
0
void Item::ccTouchesEnded( cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent )
{
    CCSetIterator iter = pTouches->begin();
    for (; iter != pTouches->end(); iter++)
    {
        CCTouch* pTouch = (CCTouch*)(*iter);
        CCPoint location = pTouch->getLocation();
        float dis = ccpDistance(location, getPosition());
        if ( dis < m_collisionRadius )
        {
            ItemTouchesEnded();
        }
    }
}
Example #26
0
void HelloWorld::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    switch (pTouches->count()) {
        case 1:
        {
            CCPoint curPoint = ((CCTouch *)pTouches->anyObject())->getLocation();
            CCPoint translation = ccpSub(this->m_LastPoint,curPoint);
            CCPoint newPos = ccpSub(m_pTileMap->getPosition(), translation);
            if (this->isAllowMove(newPos,m_pTileMap->getScale())) {
                m_pTileMap->setPosition(newPos);
            }else{
                this->m_LastPoint = ((CCTouch *)pTouches->anyObject())->getLocation();
            }
        }
            break;
        case 2:
        {
            CCSetIterator iter;
            CCPoint pt[2];
            int i = 0;
            for (iter = pTouches->begin(); iter != pTouches->end(); iter++) {
                CCTouch *touch = (CCTouch *)*iter;
                pt[i++] = touch->getLocation();
            }
            
            this->m_CurDistance = ccpDistance(pt[0],pt[1]);
            
            float changedScale = this->m_CurDistance/this->m_BeganDistance;
            float nowScale = this->m_LastScale - 1 + changedScale;
            nowScale = MIN(nowScale,MAXSCALE);
            nowScale = MAX(nowScale,MINSCALE);
            
            
            if (this->m_LastScale > nowScale) {
                CCPoint newPos = ccpSub(m_pTileMap->getPosition(), ccpMult(ccpNormalize(m_pTileMap->getPosition()), ccpLength(m_pTileMap->getPosition())*(this->m_LastScale - nowScale)/(this->m_LastScale -MINSCALE)));
                
                CCLog("scale:%f--newPos:%f,%f--%d",nowScale,m_pTileMap->getPositionX(),m_pTileMap->getPositionY(),isAllowMove(newPos, nowScale));
                if (isAllowMove(newPos,nowScale)) {
                    m_pTileMap->setPosition(newPos);
                }
            }
            
            m_pTileMap->setScale(nowScale);
        }
            break;
        default:
            break;
    }
}
Example #27
0
void DirectBurn::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    if (m_fireBall)
    {
        CCSetIterator iter = pTouches->begin();
        for (; iter != pTouches->end(); iter++)
        {
            CCTouch* pTouch = (CCTouch*)(*iter);
            CCPoint touchPos = pTouch->getLocation();

            m_fireBall->setPosition(touchPos);
            m_pStreak->setPosition(touchPos);
        }
    }
}
Example #28
0
void WallSingleScene::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent){
	CCLog("ccTouchesMoved");
	CCTouch* pTouch = (CCTouch*)pTouches->anyObject();
	if (ccpDistance(prePoint,pTouch->getLocation()) > 50)
	{
		isMoved = true;
	}
	CCPoint newpos=ccp(pTouch->getLocation().x , pTouch->getLocation().y);
	CCPoint temppoint=ccp(newpos.x-touchbeginpoint.x, newpos.y-touchbeginpoint.y);
	changepoint =ccp(changepoint.x+temppoint.x, changepoint.y+temppoint.y);
	////////////////
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();

	if(changepoint.y!=0)
		changepoint.y=0;

	if(changepoint.x>=0)
		changepoint.x=0;

	if (changepoint.x<=-900*rescale+visibleSize.width)
		changepoint.x=-900*rescale+visibleSize.width;
	////////////////
	touchbeginpoint = newpos;
}
void BaseContentWrapLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	if (!mBaseScene->getCollisionEnable())
	{
		return;
	}

	CCTouch* touch = (CCTouch*)(*(pTouches->begin()));
    if(touch->getID() != 0 || pTouches->count() > 1)
        return;
    
	mScrollControler->stopScrolling();
	mVCalculate->clearRecord();
	mLastTouchPos = touch->getLocation();
}
Example #30
0
void GameState::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
	CCSetIterator it = pTouches->begin();
	CCTouch* touch = (CCTouch*)(*it);
	CCPoint location = touch->getLocation();

	this->touchPoint = location;
	if(isPressReload &&
		stageManager->getPlayer()->weaponManager->containPointWithReloadSpr(touchPoint))
	{
		stageManager->getPlayer()->weaponManager->pressingReloadSpr();
	}
	else
		stageManager->getPlayer()->weaponManager->nonPressingReloadSpr();
}