void Joystick::onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event) { std::vector<Touch*>::const_iterator touchIter = touches.begin(); Touch* touch = (Touch*)(*touchIter); if(m_pJoystick->getBoundingBox().containsPoint(touch->getLocation())) { this->showJoystick(); updateJoystick(touch); CCLOG("***"); CCLOG("update touch:%f %f",touch->getLocation().x,touch->getLocation().y); return; } }
void SelectStage::onTouchesEnded(const vector<Touch *> & touches, Event * event) { vector<Touch *>::const_iterator it = touches.begin(); while (it != touches.end()) { Touch * touch = (Touch *) (* it); if (touch) { Point tap = touch->getLocation(); Rect select; Scene * gameScene; select = _stageSun->getBoundingBox(); if (select.containsPoint(tap)) { gameScene = TransitionFlipY::create(0.5f,GameLayer::scene(),TransitionScene::Orientation::RIGHT_OVER); Director::getInstance()->replaceScene(gameScene); } else if (!select.containsPoint(tap) && _stageSea->getBoundingBox().containsPoint(tap)) { // gameScene = TransitionFlipY::create(0.5f, GameLayer::scene(), TransitionScene::Orientation::RIGHT_OVER); // Director::getInstance()->replaceScene(gameScene); } else { } } it++; } }
void PlaySceneOne::onTouchMoved(Touch* touches, Event* event) { log("touchMMMMMMMMMOOVVEDDD执行了---------------------------------------------"); // 获取当前触摸的目标 Touch* touch = static_cast<Touch*>(touches); Point locationInNodelocal = touch->getLocation(); //log("GameObjHero::onTouchBegan::rx=%0.2f, ry=%0.2f, rw=%0.2f, rh=%0.2f, lx=%0.2f, ly=%0.2f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height, locationInNode.x, locationInNode.y); //左侧手势 if (ControlrectMove.containsPoint(locationInNodelocal)) { float adsxL = locationInNodelocal.x - proposL.x; float adsyL = locationInNodelocal.y - proposL.y; hero->locationInNode = locationInNodelocal; if (adsxL <= -50 && hero->state != 1) { //减少手抖的影响且主角不在空中 proposL = locationInNodelocal; // 设置运动状态:左移 hero->setState(3); log("MMMMMMMMMOOOOOOOOVVVVEEEEE1"); } else if (adsxL >= 50 && hero->state != 1) { proposL = locationInNodelocal; // 设置运动状态:右移 hero->setState(4); log("MMMMMMMMMOOOOOOOOVVVVEEEEE2"); } } //右上手势 else if (ControlrectShot.containsPoint(locationInNodelocal)) { log("shotmoved"); proposM = locationInNodelocal;////////////////////////; hero->archAngle = locationInNodelocal; hero->rotateArrow(hero->archAngle); hero->setState(7); } }
void CocosDenshionTest::ccTouchesMoved(Set *pTouches, Event *pEvent) { Touch* touch = (Touch*)pTouches->anyObject(); Point touchLocation = touch->getLocation(); float nMoveY = touchLocation.y - _beginPos.y; Point curPos = _itmeMenu->getPosition(); Point nextPos = ccp(curPos.x, curPos.y + nMoveY); if (nextPos.y < 0.0f) { _itmeMenu->setPosition(PointZero); return; } if (nextPos.y > ((_testCount + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)) { _itmeMenu->setPosition(ccp(0, ((_testCount + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))); return; } _itmeMenu->setPosition(nextPos); _beginPos = touchLocation; }
void QTELayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event) { if(!enableFight) return; Touch *touch = touches.at(0); Vec2 delta = touch->getDelta(); Vec2 lastPos = touch->getPreviousLocation(); Vec2 pos = touch->getLocation(); float dx = pos.x - startTouchPosition.x; float dy = pos.y - startTouchPosition.y; float dist = sqrtf(dx*dx+dy*dy); streak->setPosition(pos); //刀的判断 dist = pos.distanceSquared(startTouchPosition); if (dist > 50) { //hit test monster bool hit = qteMonster->hittestPoint(pos); if (hit) { hitQteMonster(); } } }
void BLevelMenu::ccTouchesMoved(Set *pTouches, Event *pEvent) { Touch* touch = (Touch*)pTouches->anyObject(); Point touchLocation = touch->getLocation(); float nMoveY = touchLocation.y - beginPos.y; Point curPos = itemMenu->getPosition(); Point nextPos = Point(curPos.x, curPos.y + nMoveY); if (nextPos.y < 0.0f) { itemMenu->setPosition(Point::ZERO); return; } if (nextPos.y > ((levelCount + 1)* LINE_SPACE - visRect.size.height)) { itemMenu->setPosition(Point(0, ((levelCount + 1)* LINE_SPACE - visRect.size.height))); return; } itemMenu->setPosition(nextPos); beginPos = touchLocation; s_tCurPos = nextPos; }
void Game2DStage::touchHandler(JniMethodInfo nativeTouchCallbackMInfo, std::string type, std::vector<cocos2d::Touch *> &touches){ jstring jType = nativeTouchCallbackMInfo.env->NewStringUTF(type.c_str()); int len = touches.size()*2; jfloat buf[len]; jfloatArray arr = nativeTouchCallbackMInfo.env->NewFloatArray(len); Touch *t = NULL; Point p; int index = 0; for (auto it = touches.begin(); it!=touches.end(); it++) { t = (Touch*)(*it); p = t->getLocation(); buf[index] = p.x;index++; buf[index] = p.y;index++; } nativeTouchCallbackMInfo.env->SetFloatArrayRegion(arr, 0, len, buf); nativeTouchCallbackMInfo.env->CallStaticVoidMethod(nativeTouchCallbackMInfo.classID, nativeTouchCallbackMInfo.methodID,jType,arr); nativeTouchCallbackMInfo.env->DeleteLocalRef(jType); nativeTouchCallbackMInfo.env->DeleteLocalRef(arr); }
void LHScenePhysicsTransformationsDemo::onTouchesBegan(const std::vector<Touch*>& touches, Event* event) { if(touches.size() < 1){ return; } Touch* touch = touches[0]; Point location = touch->getLocation(); __Array* allPhysicalChildren = this->getGameWorldNode()->getChildrenOfType<Node*>(); for(int i = 0; i < allPhysicalChildren->count(); ++i) { Node* node = (Node*)allPhysicalChildren->getObjectAtIndex(i); if(node && node->getBoundingBox().containsPoint(location)) { // node->removeFromParent();//this will remove the node together with its physical body (if any) CCLOG("SETTING NODE %p TO LOCATION %f %f", node, location.x, location.y); node->setPosition(location); node->setRotation(LHUtils::LHRandomFloat(0, 360)); node->setScaleX(LHUtils::LHRandomFloat(0.2, 1.5f)); node->setScaleY(LHUtils::LHRandomFloat(0.2, 1.5f)); return; } } //dont forget to call super LHScene::onTouchesBegan(touches, event); }
void GameLayer::onTouchesMoved(const std::vector<Touch*>& touches, Event * event) { if(_gameOver || _is_character_moving) return; Touch* touch = touches[0]; Vec2 location = touch->getLocation(); }
void MotionStreakTest2::ccTouchesMoved(Set* touches, Event* event) { Touch* touch = static_cast<Touch*>( touches->anyObject() ); Point touchLocation = touch->getLocation(); streak->setPosition( touchLocation ); }
void Joystick::onTouchesMoved(const std::vector<Touch *> &touches, Event *event) { if (_isPressed) { Touch *touch = touches[0]; Vec2 touchPoint = touch->getLocation(); this->updateVelocity(touchPoint); } }
void GameLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event * event) { if(_gameOver || _is_character_moving) return; Touch* touch = touches[0]; Vec2 location = touch->getLocation(); _startTouchPoint = location; _touchingTime = 0; _isTouching = true; }
void Joystick::onTouchesBegan(const std::vector<Touch *> &touches, Event *event) { Touch *touch = touches[0]; Vec2 touchPoint = touch->getLocation(); if (isPointInCircle(touchPoint, _center, _joystickRadius)) { _isPressed = true; this->updateVelocity(touchPoint); } }
void OperateLayer::onTouchesBegan(const vector<Touch*>& touches, Event *unused_event) { Size winSize = Director::getInstance()->getWinSize(); vector<Touch*>::const_iterator touchIter = touches.begin(); while(touchIter != touches.end()) { Touch *pTouch = (Touch*)(*touchIter); Point p = pTouch->getLocation(); ++ touchIter; } }
void SelectStage::onTouchesMoved(const vector<Touch *> & touches, Event * event) { vector<Touch *>::const_iterator it = touches.begin(); while (it != touches.end()) { Touch * touch = (Touch *) (* it); if (touch) { Point tap = touch->getLocation(); } } }
void Joystick::onTouchesBegan(const std::vector<Touch*>& touches, Event *event) { Touch* touch = touches[0]; Vec2 touchPoint = touch->getLocation(); if (isPointInCircle(touchPoint, kCenter, JOYSTICK_RADIUS)) { isPressed = true; this->updateVelocity(touchPoint); } }
void HelloWorld::onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *pEvent) { auto it = touches.begin(); //ループですべてのタッチを処理 while (it != touches.end()) { Touch* touch = (Touch*)(*it); auto location = touch->getLocation(); CCLOG("x:%f y:%f", location.x, location.y); it++; } }
void Joystick::onTouchesBegan(const std::vector<Touch*> &touches, Event* unused_event) { for (auto it : touches) { Touch* touch = it; if (_isTouchShow) { centerPos = touch->getLocation(); joystick_limit->setPosition(centerPos); joystick_control->setPosition(centerPos); this->setVisible(true); } // 조이스틱 - 리미트 공간안에서 시작을 하였다면 if (isTouchCircle(touch->getLocation(), centerPos, joystick_limit->getContentSize().width / 4)) { _isTouch = true; controlerPos = touch->getLocation(); } } }
void Joystick::onTouchesMoved(const std::vector<Touch*> &touches, Event* unused_event) { for (auto it : touches) { Touch* touch = it; if (_isTouch) { float limitSize = joystick_limit->getContentSize().width / 4; // 제한 범위의 반지름 // 터치가 리미트 범위를 넘었을 시에 컨트롤러가 끝부분에 남아있게 하기 위함 if (!(isTouchCircle(touch->getLocation(), centerPos, limitSize))) { Point touchPos = touch->getLocation(); // 터치 위치값 float dX = touchPos.x - centerPos.x; float dY = touchPos.y - centerPos.y; float distance = sqrt(dX*dX + dY*dY); // 대각선 길이 구하기 float angle = atan2(dY, dX); // 각도 구하기 if (distance > limitSize) { dX = cos(angle) * limitSize; dY = sin(angle) * limitSize; touchPos.x = centerPos.x + dX; touchPos.y = centerPos.y + dY; } controlerPos = Vec2(touchPos); } else { controlerPos = touch->getLocation(); } } } }
void CWidgetWindow::onTouchesBegan(const std::vector<Touch*>&touches, Event *unused_event) { for(unsigned int i=0;i<touches.size(); i++) { Touch* pTouch = touches.at(i); if( m_bTouchEnabled && m_bMultiTouchEnabled && _visible && _children.size() > 0 ) { Vec2 touchPointInView = convertToNodeSpace(pTouch->getLocation()); for(int j=_children.size()-1;j>=0;--j){ Node* pNode = _children.at(j); CWidget* pWidget = dynamic_cast<CWidget*>(pNode); if( pWidget && pNode->isVisible() && pWidget->isEnabled() && pWidget->isTouchEnabled() ) { bool bSameWidgetBreak = false; if( pNode->getBoundingBox().containsPoint(touchPointInView) ) { //make sure it can not happened on the same widget map<int, __ccMULTITOUCHTARGET>::iterator mitr = m_mMultiTouchKeeper.begin(); for(; mitr != m_mMultiTouchKeeper.end(); ++mitr) { if( mitr->second.pWidget == pWidget ) { bSameWidgetBreak = true; break; } } if( bSameWidgetBreak ) { break; } if( pWidget->executeTouchBeganHandler(pTouch) != eWidgetTouchNone ) { __ccMULTITOUCHTARGET tKeeper; tKeeper.fTouchedDuration = 0.000001f; tKeeper.pWidget = pWidget; tKeeper.pLongClickedWidgetObject = NULL; m_mMultiTouchKeeper[pTouch->getID()] = tKeeper; return; } } } } } } }
// cpp with cocos2d-x // virtualなので要実装 void HelloWorld::onTouchesEnded(const std::vector<Touch*>& touches, Event* event) { // Choose one of the touches to work with Touch* touch = touches[0]; Point location = touch->getLocation(); log("++++++++after x:%f, y:%f", location.x, location.y); // Set up initial location of projectile Size winSize = Director::getInstance()->getVisibleSize(); auto origin = Director::getInstance()->getVisibleOrigin(); Sprite *projectile = Sprite::create("Projectile.png", Rect(0, 0, 20, 20)); projectile->setPosition( Point(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 // case1 // 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; Point realDest = Point(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( Sequence::create( MoveTo::create(realMoveDuration, realDest), CallFuncN::create(CC_CALLBACK_1(HelloWorld::spriteMoveFinished, this)), NULL) ); // Add to projectiles array projectile->setTag(2); _projectiles->addObject(projectile); // 効果音 case4 // CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("pew-pew-lei.wav"); }
void QTELayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event) { if(!enableFight) return; Touch *touch = touches.at(0); Vec2 pos = touch->getLocation(); //this->getChildByTag(111)->setPosition(Vec2(t->getLocation().x,t->getLocation().y)); //star->setPosition(pos); streak->setPosition(pos); streak->reset(); startTouchPosition = pos; currentTouchTime = millisecondNow(); }
void GameLayer::onTouchesEnded(const std::vector<Touch*>& touches, Event * event) { if(_gameOver || _is_character_moving) return; Touch* touch = touches[0]; Vec2 location = touch->getLocation(); if(_isTouching && _touchingTime <= SWIPE_TIME) { _calculateSwipe(location); } _touchingTime = 0; _isTouching = false; }
void PlayerController::onTouchesEnded(const std::vector<Touch*>& touches, Event *event) { // Choose one of the touches to work with Touch* touch = touches[0]; Point location = touch->getLocation(); Sprite *projectile = Sprite::create("components/Projectile.png", Rect(0, 0, 20, 20)); _owner->getParent()->addChild(projectile, 1, 4); ProjectileController *com = ProjectileController::create(); projectile->addComponent(com); com->move(location.x, location.y); ((ComAudio*)(_owner->getComponent("Audio")))->playEffect("pew-pew-lei.wav"); }
void PlayerController::ccTouchesEnded(Set *pTouches, Event *pEvent) { // Choose one of the touches to work with Touch* touch = (Touch*)( pTouches->anyObject() ); Point location = touch->getLocation(); Sprite *projectile = Sprite::create("components/Projectile.png", CCRectMake(0, 0, 20, 20)); _owner->getParent()->addChild(projectile, 1, 4); ProjectileController *com = ProjectileController::create(); projectile->addComponent(com); com->move(location.x, location.y); ((ComAudio*)(_owner->getComponent("Audio")))->playEffect("pew-pew-lei.wav"); }
void Joystick::onTouchesMoved(const std::vector<Touch*>& touches, Event *event) { log("joy moved 1\nisPressed: %d", isPressed); if (isPressed) { log("joy moved 2"); Touch* touch = touches[0]; Vec2 touchPoint = touch->getLocation(); this->updateVelocity(touchPoint); log("fishingGauge: %d", fishingGauge); fishingGauge+= 4; } }
void LHScenePulleyJointDemo::onTouchesMoved(const std::vector<Touch*>& touches, Event* event){ if(touches.size() < 1){ return; } Touch* touch = touches[0]; Point touchLocation = touch->getLocation(); touchLocation = this->getGameWorldNode()->convertToNodeSpace(touchLocation); this->setTargetOnMouseJoint(touchLocation); //dont forget to call super LHScene::onTouchesMoved(touches, event); }
void OperateLayer::onTouchesMoved(const vector<Touch*>& touches, Event *unused_event) { Size winSize = Director::getInstance()->getWinSize(); std::vector<Touch*>::const_iterator touchIter = touches.begin(); Touch *pTouch = (Touch*)(*touchIter); Point start = pTouch->getStartLocation(); if(start.x > winSize.width / 2) { return; } Point dest = pTouch->getLocation(); float distance = start.getDistance(dest); Point direction = (dest - start).normalize(); this->updateJoystick(direction, distance); m_pHero->walk(direction, distance); }
void Box2DTestLayer::ccTouchesEnded(Set* touches, Event* event) { //Add a new body/atlas sprite at the touched location SetIterator it; Touch* touch; for( it = touches->begin(); it != touches->end(); it++) { touch = static_cast<Touch*>(*it); if(!touch) break; Point location = touch->getLocation(); addNewSpriteAtPosition( location ); } }
void Joystick::onTouchesBegan(const std::vector<Touch*>& touches, Event *event) { log("joy touch1"); Touch* touch = touches[0]; Vec2 touchPoint = touch->getLocation(); log("joy touchPoint x: %f y: %f", touchPoint.x, touchPoint.y); log("joy kCenter x: %f y: %f", kCenter.x, kCenter.y); if (isPointInCircle(touchPoint, kCenter, JOYSTICK_RADIUS)) { log("joy touch2"); isPressed = true; this->updateVelocity(touchPoint); doJoyAnimate(1); soundEffect->doSoundAction("game", 17); } }