void CCTouchDispatcher::OnPointerOff(const InputPointerEvent* evt) { map<Ref<InputPointer>, CCTouch*>::type::iterator itr = m_Touches.find(evt->getSource()); if (itr == m_Touches.end()) return; CCSet set; CCTouch* pTouch = itr->second; m_Touches.erase(itr); pTouch->SetTouchInfo(0, evt->getPos().x, evt->getPos().y); set.addObject(pTouch); // LOG(0, ".. off %.3f %.3f\n", evt->GetPos().x, evt->GetPos().y); touchesEnded(&set); pTouch->release(); }
void Clayer_ripple_horizontal::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event) { CCTouch* touch; for(auto it = touches.begin(); it != touches.end(); it++) { touch = (CCTouch*)(*it); if(!touch) break; CCPoint location = touch->getLocationInView(); location = CCDirector::sharedDirector()->convertToGL(location); // cout<<"mos pos:"<<location.x<<" "<<location.y<<endl; m_ripple_horizontalNode->pressAtX(location.x, 0.8); break; } }
void HudLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) { if (Utils::gameLayer()->getState() == kEditMode) { CCTouch *pTouch; CCSetIterator setIter; for (setIter = pTouches->begin(); setIter != pTouches->end(); ++setIter) { pTouch = (CCTouch *)(*setIter); _touches->addObject(pTouch); } pTouch = (CCTouch *) _touches->objectAtIndex(0); CCPoint location = pTouch->getLocation(); for (int i = 0; i < _tools->count(); i++) { Tool *tool = (Tool *) _tools->objectAtIndex(i); if (tool->touchingTool(location)) { _movingTool = i; Utils::gameLayer()->setShouldPan(false); } } } }
Boolean CCEGLView::OnPenDown(EventType* pEvent, Int32 nIndex) { if (m_pDelegate && nIndex < MAX_TOUCHES) { CCTouch* pTouch = s_pTouches[nIndex]; if (!pTouch) { pTouch = new CCTouch; } pTouch->SetTouchInfo(0, (float)(pEvent->sParam1 - m_rcViewPort.X()) / m_fScreenScaleFactor, (float)(pEvent->sParam2 - m_rcViewPort.Y()) / m_fScreenScaleFactor); s_pTouches[nIndex] = pTouch; CCSet set; set.addObject(pTouch); m_pDelegate->touchesBegan(&set, NULL); } return FALSE; }
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); } }
void Clayer_ripple_horizontal::onTouchesEnded(const std::vector<Touch*>& touches, Event *unused_event) { //Add a new body/atlas sprite at the touched location CCTouch* touch; for(auto it = touches.begin(); it != touches.end(); it++) { touch = (CCTouch*)(*it); if(!touch) break; CCPoint location = touch->getLocationInView(); location = CCDirector::sharedDirector()->convertToGL(location); // cout<<"mos pos:"<<location.x<<" "<<location.y<<endl; break; } }
void CtestLayer::ccTouchesEnded(CCSet* touches, CCEvent* event) { CCSetIterator it; CCTouch* touch; for( it = touches->begin(); it != touches->end(); it++) { touch = (CCTouch*)(*it); if(!touch) break; CCPoint pointInWinSpace = touch->getLocationInView(); //----update mos m_mosPosf=m_mosPos; m_mosPos=pointInWinSpace; } }
void HelloWorld::ccTouchesBegan(CCSet *touches,CCEvent *event){ if (_mouseJoint!=NULL) return; CCTouch *myTouch =(CCTouch*) touches->anyObject(); CCPoint location = myTouch->getLocationInView(); location = CCDirector::sharedDirector()->convertToGL(location); b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO); if (resinBallBody->_ballBody->GetFixtureList()->TestPoint(locationWorld)) { b2MouseJointDef md; md.bodyA = _groundBody; md.bodyB =resinBallBody->_ballBody; md.target =resinBallBody->_ballBody->GetWorldCenter(); md.collideConnected =true; md.maxForce =1000.0f* resinBallBody->_ballBody->GetMass(); _mouseJoint = (b2MouseJoint *)_world->CreateJoint(&md); resinBallBody->_ballBody->SetAwake(true); } }
void SceneNode::ccTouchesEnded(CCSet* touches, CCEvent* event) { touchValid=false; CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSetIterator it; CCTouch* touch; for( it = touches->begin(); it != touches->end(); it++) { touch = (CCTouch*)(*it); if(!touch) break; CCPoint loc_winSpace = touch->getLocationInView(); CCPoint loc_GLSpace = CCDirector::sharedDirector()->convertToGL(loc_winSpace); } }
void HelloWorld::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->getLocationInView(); location = CCDirector::sharedDirector()->convertToGL(location); addNewSpriteAtPosition( location ); } }
void ScrollViewDemo::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) { if (!m_bScrolling) return; CCTouch *touch = (CCTouch*)pTouches->anyObject(); CCNode *clipper = this->getChildByTag(kTagClipperNode); CCPoint point = clipper->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(touch->getLocationInView())); CCPoint diff = ccpSub(point, m_lastPoint); CCNode *content = clipper->getChildByTag(kTagContentNode); content->setPosition( ccpAdd(content->getPosition(), diff) ); m_lastPoint = point; }
void Clayer_ripple_horizontal::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->getLocationInView(); location = CCDirector::sharedDirector()->convertToGL(location); // cout<<"mos pos:"<<location.x<<" "<<location.y<<endl; break; } }
void GamePlay::ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent* event) { CCTouch* touch = (CCTouch*)(touches->anyObject()); CCPoint location = touch->getLocationInView(); location = CCDirector::sharedDirector()->convertToGL(location); int width = CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width; if(location.x < width/2) { // move left int x = mUserCar->getPositionX() - width/mNumLane; if(x > mUserCar->getContentSize().width /2) { mUserCar->setPositionX(x); } } else { // move right int x = mUserCar->getPositionX() + width/mNumLane; if(x < width - mUserCar->getContentSize().width /2) { mUserCar->setPositionX(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 ); } }
void GameLayer::ccTouchesBegan(CCSet* pTouches, CCEvent* pEvent) { for (CCSetIterator iter = pTouches->begin(); iter != pTouches->end(); ++ iter) { CCTouch* pTouch = (CCTouch*)(*iter); if (pTouch) { CCPoint tap = pTouch->getLocation(); for (int p = 0; p < 2; ++ p) { GameSprite* pGS = (GameSprite*)m_pArrPlayers->objectAtIndex(p); if (pGS->boundingBox().containsPoint(tap)) { pGS->setTouch(pTouch); } } } } }
void GameState::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) { CCTouch* touch = (CCTouch*)( pTouches->anyObject() ); CCPoint location = touch->getLocation(); touchPoint = location; pressing = true; if(stageManager->getPlayer()->weaponManager->containPointWithReloadSpr(touchPoint)) { isPressReload = true; SoundManager::getInstance()->playEffect("music/ui/ui_reload.ogg"); stageManager->getPlayer()->weaponManager->pressingReloadSpr(); } if(tutorialManager->getCurrentPage() == 5) { this->resumeSchedulerAndActions(); tutorialManager->increasePage(); } }
void BattleField::xtTouchesMoved(cocos2d::CCSet *_touches, cocos2d::CCEvent *event) { if (_touchedTroop!=NULL) { return; } CCTouch *pTouch = (CCTouch *)_touches->anyObject(); CCPoint loc = this->convertTouchToNodeSpace(pTouch); CCPoint prevoiusLoc = pTouch->getPreviousLocationInView(); //屏幕坐标变成GL坐标 prevoiusLoc = CCDirector::sharedDirector()->convertToGL(prevoiusLoc); //然后转成layer相对坐标 prevoiusLoc = this->convertToNodeSpace(prevoiusLoc); CCPoint translation = ccpSub(loc, prevoiusLoc); CCPoint next = ccpAdd(this->getPosition(), translation); this->adjustViewBoundingPosition(next); }
KDvoid TestBlade::ccTouchesBegan ( CCSet* pTouches, CCEvent* pEvent ) { for ( CCSetIterator it = pTouches->begin ( ); it != pTouches->end ( ); it++ ) { CCTouch* pTouch = (CCTouch*) ( *it ); CCPoint tLocation = this->convertTouchToNodeSpace ( pTouch ); CCBlade* pBlade = CCBlade::create ( 50 ); pBlade->setAutoDim ( KD_TRUE ); KDint nRand = kdRand ( ) % 3 + 1; CCTexture2D* pTexture = CCTextureCache::sharedTextureCache ( )->addImage ( ccszf ( "xm_supports/streak%d-hd.png", nRand ) ); pBlade->setTexture ( pTexture ); pBlade->push ( tLocation ); this->addChild ( pBlade ); m_pDictionary->setObject ( pBlade, pTouch->getID ( ) ); } }
void Box2DImport::ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent* event) { if (_mouseJoint != NULL) return; CCTouch *myTouch = (CCTouch *)touches->anyObject(); CCPoint location = myTouch->getLocationInView(); location = CCDirector::sharedDirector()->convertToGL(location); b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO); if (_iconFixture->TestPoint(locationWorld)) { b2MouseJointDef md; md.bodyA = groundBody; md.bodyB = _iconBody; md.target = locationWorld; md.collideConnected = true; md.maxForce = 1000.0f * _iconBody->GetMass(); _mouseJoint = (b2MouseJoint *)world->CreateJoint(&md); _iconBody->SetAwake(true); } }
void HelloWorld::ccTouchesBegan(cocos2d::CCSet *touches,cocos2d::CCEvent *event) { //We can choose one of the touches to work with CCTouch* touch = (CCTouch*) (touches->anyObject()); CCPoint location = touch->getLocation(); //Pick laser sprite from the projectile array and run an action on it _playerProjectiles[_playerProjectileCount]->stopAllActions(); _playerProjectiles[_playerProjectileCount]->setPosition(ccp(_player->getPositionX(),_player->getPositionY()+(_player->getScaleY()*_player->getContentSize().height))); _playerProjectiles[_playerProjectileCount]->setVisible(true); //Create a move action that is 0.4s long and moves the projectile starting from the player position to the top of the screen _playerProjectiles[_playerProjectileCount]->runAction(CCSequence::create(CCMoveTo::create(0.4f,ccp(_player->getPositionX(),_winHeight)),CCCallFuncN::create(this,callfuncN_selector(HelloWorld::spriteMoveFinished)),NULL)); ++_playerProjectileCount; //If reached the maximum number of sprites reset the the count to recycle the sprites if (_playerProjectileCount >= MAX_PLAYER_PROJECTILES) { _playerProjectileCount = 0; } CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("shoot.wav"); }
void CCEGLView::onTouchesEnd(int id[], float x[], float y[], int pointerNumber) { result r = E_SUCCESS; CCSet set; for(int i = 0 ; i < pointerNumber ; i++ ) { CCTouch *pTouch = NULL; r = s_mapTouches.GetValue(id[i], pTouch); if (E_SUCCESS == r && pTouch != NULL) { pTouch->SetTouchInfo(0, (x[i] - m_rcViewPort.origin.x) / m_fScreenScaleFactor , (y[i] - m_rcViewPort.origin.y) / m_fScreenScaleFactor); set.addObject(pTouch); s_mapTouches.Remove(id[i]); pTouch->release(); CCLOG("Ending touches with id: %d, x=%f, y=%f, retain count = %d", id[i], x[i], y[i], pTouch->retainCount()); } } m_pDelegate->touchesEnded(&set, NULL); }
// /* void Controller::ccTouchesBegan(cocos2d::CCSet *touches, cocos2d::CCEvent *pEvent) { CCTouch* touch; int idx = 0; for (CCSetIterator it = touches->begin(); it != touches->end(); it++, idx++) { touch = (CCTouch*)(*it); if (!touch) break; this->displayTouchPoint(0, 0); CCPoint point = touch->getLocation(); this->startPoint = point; CCSprite* pSprite = CCSprite::create("Controller.png"); CCSize winsize = CCDirector::sharedDirector()->getWinSize(); pSprite->setPosition( ccp(point.x, point.y)); pSprite->setScale(0.25); pSprite->setOpacity(100); this->ccTouchesMoved(touches, pEvent); this->addChild(pSprite, 1, 2 + idx); } }
void Clayer_ripple_horizontal::ccTouchesMoved(CCSet* touches , CCEvent* event) { CCSetIterator it; CCTouch* touch; for( it = touches->begin(); it != touches->end(); it++) { touch = (CCTouch*)(*it); if(!touch) break; CCPoint location = touch->getLocationInView(); location = CCDirector::sharedDirector()->convertToGL(location); // cout<<"mos pos:"<<location.x<<" "<<location.y<<endl; m_ripple_horizontalNode->pressAtX(location.x, 0.8); break; } }
void HelloWorld::ccTouchesEnded(CCSet *touches, CCEvent *event) { CCTouch * touch = (CCTouch*)touches->anyObject(); CCPoint location = touch->locationInView(touch->view()); location = CCDirector::sharedDirector()->convertToGL(location); CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSprite* projectile = CCSprite::spriteWithFile("Projectile.png", CCRectMake(0, 0, 20, 20)); projectile->setPosition(ccp(20, size.height/2)); int offX = location.x - projectile->getPosition().x; int offY = location.y - projectile->getPosition().y; if (offX <= 0) return; CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("pew-pew-lei.wav"); this->addChild(projectile); projectile->setTag(2); _projectiles->addObject(projectile); // Determine where we wish to shoot the projectile to int realX = size.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 = 240/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) ); }
void Clayer_break::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event) { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCTouch* touch; for(auto it = touches.begin(); it != touches.end(); it++) { touch = (CCTouch*)(*it); if(!touch) break; CCPoint loc_winSpace = touch->getLocationInView(); CCPoint loc_GLSpace = CCDirector::sharedDirector()->convertToGL(loc_winSpace); } }
void SelectionRecognizer::checkForSelection(CCObject* obj) { CCTouch* touch = (CCTouch*)obj; //the touch could have been discarded in the meantime if(isTouchInSelection(touch)) { CCPoint currentLocation = Scene::touchPosition(touch); CCPoint touchOrigin = TOPOINT(storedTouches->objectForKey(touch->getID())); CCObject* target = mainLinker->linkedObjectOf(touch); if(ccpDistance(Scene::touchPosition(touch), touchOrigin) <= maxMovement) { CCNotificationCenter::sharedNotificationCenter()->postNotification("SelectionRecognized", DcreateP(touch, Screate("Touch"), target, Screate("Target"), NULL)); } else { CCNotificationCenter::sharedNotificationCenter()->postNotification("SelectionCanceled", DcreateP(touch, Screate("Touch"), storedTouches->objectForKey(touch->getID()), Screate("Origin"), target, Screate("Target"), NULL)); } storedTouches->removeObjectForKey(touch->getID()); } }
void ToyLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) { CCSetIterator it; CCTouch* touch; for ( it = pTouches->begin(); it != pTouches->end(); it++) { touch = (CCTouch*)(*it); if(!touch) break; CCPoint location = touch->getLocation(); b2Vec2 pos = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO); if (this->mouseJoint) { this->mouseJoint->SetTarget(pos); } } }
void RenderTextureZbuffer::ccTouchesMoved(CCSet* touches, CCEvent* event) { CCSetIterator iter; CCTouch *touch; for (iter = touches->begin(); iter != touches->end(); ++iter) { touch = (CCTouch *)(*iter); CCPoint location = touch->locationInView(touch->view()); location = CCDirector::sharedDirector()->convertToGL(location); sp1->setPosition(location); sp2->setPosition(location); sp3->setPosition(location); sp4->setPosition(location); sp5->setPosition(location); sp6->setPosition(location); sp7->setPosition(location); sp8->setPosition(location); sp9->setPosition(location); } }
void StadionLayer::ccTouchesEnded(CCSet* touches, CCEvent* event) { if (_gameState == kGameOver || _gameState == kGamePaused || !getGameConfig()->touchAllowed()) { return; } CCTouch *touch = (CCTouch *)touches->anyObject(); if(touch && !_shooting) { ObserverData* data = new ObserverData(); data->setInitialPosition(_shootStartPoint); data->setFinalPosition(touch->getLocation()); CCNotificationCenter::sharedNotificationCenter()->postNotification(START_SHOOT, data); } }
void SceneNode::ccTouchesBegan(CCSet* touches, CCEvent* event) { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSetIterator it; CCTouch* touch; for( it = touches->begin(); it != touches->end(); it++) { touch = (CCTouch*)(*it); if(!touch) break; CCPoint loc_winSpace = touch->getLocationInView(); // CCLOG("loc_winSpace:%f,%f",loc_winSpace.x,loc_winSpace.y); if(loc_winSpace.x>0&&loc_winSpace.x<winSize.width&&loc_winSpace.y>0&&loc_winSpace.y<winSize.height){ touchPos_winSpace=loc_winSpace; touchValid=true; } } }