bool UIBuyBuildingLayer::isTouchEdge(Touch* touch) { Point local = convertToNodeSpace(touch->getLocation()); auto rect = Rect(0,317 + 100,Director::getInstance()->getWinSize().width,Director::getInstance()->getWinSize().height - 417); if (rect.containsPoint(local)) { return true; } return false; }
void CCLayerPanZoom::setScaleY(float fScaleY) { fScaleY = (MIN(MAX(fScaleY, _minScale), _maxScale)); CCPoint winOrigin = CCDirector::sharedDirector()->getVisibleOrigin(); CCSize winSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint screenCenter = ccp(winOrigin.x + winSize.width * 0.5f, winOrigin.y + winSize.height * 0.5f); CCPoint centerBefore = convertToNodeSpace(screenCenter); CCNode::setScaleY(fScaleY); CCPoint centerAfter = convertToNodeSpace(screenCenter); CCPoint centerPointDelta = ccpSub(centerAfter,centerBefore); centerPointDelta = ccpMult(centerPointDelta, fScaleY); move(centerPointDelta); }
CWidgetTouchModel CSlider::onTouchBegan(CCTouch *pTouch) { if (!m_bDragable) { return eWidgetTouchNone; } m_bDrag = m_pSlider->boundingBox().containsPoint( convertToNodeSpace(pTouch->getLocation()) ); if( m_bDrag ) { changeValueAndExecuteEvent(valueFromPoint(convertToNodeSpace(pTouch->getLocation())), true); return eWidgetTouchSustained; } return eWidgetTouchNone; }
bool Layout::hitTest(const CCPoint &pt) { CCPoint nsp = convertToNodeSpace(pt); CCRect bb = CCRect(0.0f, 0.0f, _size.width, _size.height); if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height) { return true; } return false; }
bool Widget::hitTest(const Point &pt) { Point nsp = convertToNodeSpace(pt); Rect bb = Rect(-_size.width * _anchorPoint.x, -_size.height * _anchorPoint.y, _size.width, _size.height); if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height) { return true; } return false; }
///////////////////////////////////////////////////////// // Touch on left side of screen moves player left // Touch on right side of screen moves player right void GameScene::ccTouchEnded(CCTouch* touch, CCEvent* event) { CCPoint touchLocation = touch->getLocationInView( ); touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation); touchLocation = convertToNodeSpace(touchLocation); float touchCenter = CCDirector::sharedDirector()->getWinSize().width/2 - touchLocation.x; float accel_filter = 0.1f; bird_vel.x = bird_vel.x * accel_filter - touchCenter; }
bool Box2DView::ccTouchBegan(CCTouch* touch, CCEvent* event) { CCPoint touchLocation = touch->locationInView( touch->view() ); touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation ); CCPoint nodePosition = convertToNodeSpace( touchLocation ); // NSLog(@"pos: %f,%f -> %f,%f", touchLocation.x, touchLocation.y, nodePosition.x, nodePosition.y); return m_test->MouseDown(b2Vec2(nodePosition.x,nodePosition.y)); }
bool GameSprite_Gold::isTouchInside( CCTouch* touch ) { CCPoint touchLocation = touch->getLocation(); // Return to GL coordinates CCPoint localPos = convertToNodeSpace(touchLocation); CCRect rc = rect(); rc.origin = CCPointZero; bool isTouched = rc.containsPoint(localPos); return isTouched; }
bool CCSpriteEx::isTouchInside( CCTouch* touch ) { CCPoint touchLocation = touch->getLocation(); // 返回GL坐标 CCPoint localPos = convertToNodeSpace(touchLocation); CCRect rc = rect(); rc.origin = CCPointZero; bool isTouched = rc.containsPoint(localPos); return isTouched; }
void CCutScene::checkFoodSliced() { if (m_nSliceCount >= 8) { //todo:暂时不能切,播放庆祝特效 m_nSliceCount = 0; CFoodCut* pFood = NULL; int nIndex = -1; int nCount = m_vCutFoods.size(); for (int i = 0; i < nCount; i++) { pFood = m_vCutFoods[i]; if (pFood != NULL) { nIndex = pFood->getTouchedIndex(); Vec2 v2Dest = convertToNodeSpace(m_pContentLayer->convertToWorldSpace(PANZI_POSITION[nIndex])); float fSpeed = 1200; float fDis = pFood->getPosition().distance(v2Dest); pFood->runAction(Sequence::create(DelayTime::create(0.08f * i), MoveTo::create(fDis / fSpeed, v2Dest), CallFunc::create([this, pFood, nCount, nIndex](){ static int nTmp = 0; nTmp ++; if (nTmp >= nCount) { nTmp = 0; //todo: 在盘子上创建碎食材 std::vector<int> vMaterials = pFood->getMaterials(); MATERIAL_ID eId = MI_MAX; if (vMaterials.size() != 0) { eId = (MATERIAL_ID)vMaterials[0]; } int aTastes[TT_MAX] = {0}; CFoodPiece* pFoodPiece = CFoodPiece::create(eId); if (pFoodPiece != NULL) { pFoodPiece->initProperty(FT_SUIPIAN, vMaterials, aTastes); m_pContentLayer->addChild(pFoodPiece, 1); pFoodPiece->setPosition(PANZI_POSITION[nIndex]); } CGlobalData::getSingleton()->setPanziFood(pFood->getPanziIndex(), pFood); } pFood->removeFromParent(); }), NULL)); } } m_vCutFoods.clear(); m_bHasFood = false; } }
void BBAbstractSceneView::onTouchScaleBegin(float nDistance, float nFocusX, float nFocusY) { m_ptScaleBeginFocus = ccp(nFocusX, nFocusY); m_nScaleBeginScale = getScale(); m_nScaleBeginDistance = nDistance; CCSize cs = getContentSize(); m_ptScaleBeginFocusRate = convertToNodeSpace(m_ptScaleBeginFocus); m_ptScaleBeginFocusRate.x/=cs.width; m_ptScaleBeginFocusRate.y/=cs.height; };
void ScrollViewDemo::onTouchesMoved(const std::vector<Touch*>& touches, Event *event) { if (!_scrolling) return; Touch *touch = touches[0]; auto clipper = this->getChildByTag(kTagClipperNode); auto point = clipper->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView())); Vec2 diff = point - _lastPoint; auto content = clipper->getChildByTag(kTagContentNode); content->setPosition(content->getPosition() + diff); _lastPoint = point; }
bool RCCheckButton::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { bool bRet = false; CCRect checkBtnRect = getNodeRect(); if(checkBtnRect.containsPoint(convertToNodeSpace(pTouch->getLocation()))) { m_pText->setColor(m_selectedLabelColor); bRet = true; } return bRet; }
bool Slider::onTouchBegan(Touch *touch, Event *unusedEvent) { bool pass = Widget::onTouchBegan(touch, unusedEvent); if (_hitted) { Vec2 nsp = convertToNodeSpace(_touchBeganPosition); setPercent(getPercentWithBallPos(nsp.x)); percentChangedEvent(); } return pass; }
bool Widget::hitTest(const Vec2 &pt) { Vec2 nsp = convertToNodeSpace(pt); Rect bb; bb.size = _contentSize; if (bb.containsPoint(nsp)) { return true; } return false; }
bool Slider::onTouchBegan(CCTouch *touch, CCEvent *unused_event) { bool pass = Widget::onTouchBegan(touch, unused_event); if (_hitted) { CCPoint nsp = convertToNodeSpace(_touchStartPos); setPercent(getPercentWithBallPos(nsp.x)); percentChangedEvent(); } return pass; }
void BaseBug::onEnter(){ //接收对象, 优先级,ture时阻止其他类的move and end CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, CC_MAX_TOUCHES,true); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCPoint p = ccp(s.width/2, s.height/2); p = convertToNodeSpace(p); loaderBug(p); rotationToPoint(p); moveToPoint(p); CCSprite::onEnter(); }
void SpinoffDragAndDrop::update(float dt) { if (_state != State::STAY) { cocos2d::Vec2 p0 = convertToNodeSpace(getParent()->getPosition()); cocos2d::Vec2 p1 = _texture->getPosition(); Utils::Spline<cocos2d::Vec3> spline; spline.AddKey(cocos2d::Vec3(p0.x, p0.y, 10.0f)); spline.AddKey(cocos2d::Vec3(p1.x, p1.y, 70.0f)); spline.CalculateGradient(); _strip->setVisible(true); _strip->setStripGeometry(spline); if (!World::Instance().GetTutorialManager().IsTutorialStateAvailable("ReadyToCreateSpinoff")) { if (!_isAttracting) { float shift_dist = 50.0f; float shift_speed = 3.0f; cocos2d::Vec2 screen = cocos2d::Director::getInstance()->getVisibleSize(); cocos2d::Vec2 origin = cocos2d::Director::getInstance()->getVisibleOrigin(); cocos2d::Rect bounds; bounds.origin = origin + cocos2d::Vec2(shift_dist, shift_dist); bounds.size = screen - cocos2d::Vec2(shift_dist, shift_dist) * 2.0f; if (!bounds.containsPoint(_touchWorld)) { cocos2d::Vec2 p0 = origin+screen/2.0f; cocos2d::Vec2 p1 = _touchWorld; _projector->ShiftView((p0-p1).getNormalized() * shift_speed); _projector->Update(); _worldMapLayer->UpdateMapElements(); _texture->setPosition(convertToNodeSpace(_touchWorld)); } } } } else { _strip->setVisible(false); } }
bool DragItemImage::onTouchBegan(Touch* touch, Event* event) { log("onTouchBegan"); auto target = static_cast<DragItemImage*>(event->getCurrentTarget()); Point locationInNode = target->convertToNodeSpace(touch->getLocation()); Size s = target->getContentSize(); Rect rect = Rect(0, 0, s.width, s.height); if (rect.containsPoint(locationInNode) && target->sum > 0) { target->isDragged = true; return true; } return false; }
bool CustomOneTouchListView::init() { if (!ListView::init()) { return false; } _canHandleLogic = true; schedule([this](float delta){ Size size = getContentSize(); for (auto& p : getChildren()) { Vec2 bottomleft = convertToNodeSpace(p->convertToWorldSpace(Vec2::ZERO)); Vec2 topright = convertToNodeSpace(p->convertToWorldSpace(Vec2(p->getContentSize()))); if (bottomleft.x > size.width || topright.x < 0 || bottomleft.y > size.height || topright.y < 0) { p->setVisible(false); } else p->setVisible(true); } }, "checkout"); return true; }
bool CircleEntity::intersect(Vec2 pos, float radius) { auto distance = this->getPosition().distance(pos); auto thisRadius = this->getRadius(); if (distance < (thisRadius + radius)) return true; for (auto o : orbits) { if (o->e->intersect(convertToNodeSpace(pos), radius)) { return true; } } return false; }
void RCCheckButton::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) { CCRect checkBtnRect = getNodeRect(); if(checkBtnRect.containsPoint(convertToNodeSpace(pTouch->getLocation()))) { m_pText->setColor(m_selectedLabelColor); } else { m_pText->setColor(m_normalLabelColor); } }
void CMenuItemWithDesciption::MouseMove(Point pos) { if(isVisible() && getNormalImage()->getBoundingBox().containsPoint(convertToNodeSpace(pos))) { m_IsCursorUnder = true; } else { m_IsCursorUnder = false; m_CursorOverTime = 0.0f; } }
bool LevelStartView::onPropTouchBegan(cocos2d::Touch* touch, cocos2d::Event *event) { auto target = static_cast<Sprite*>(event->getCurrentTarget()); Point locationInNode = target->convertToNodeSpace(touch->getLocation()); Size s = target->getContentSize(); Rect rect = Rect(0, 0, s.width, s.height); if (rect.containsPoint(locationInNode)) { selectedPropClick(target); return true; } return false; }
bool Ajustes::comprobarToque(cocos2d::Touch *touch,Sprite *sprite){ auto target = sprite; Point locationInNode = target->convertToNodeSpace(touch->getLocation()); Size s = target->getContentSize(); Rect rect = Rect(0, 0, s.width, s.height); if (rect.containsPoint(locationInNode)) { return true; }else{ return false; } }
void RCCheckButton::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) { CCRect checkBtnRect = getNodeRect(); if(checkBtnRect.containsPoint(convertToNodeSpace(pTouch->getLocation()))) { toggleSelected(); if(m_pListener && m_pfnSelector) { (m_pListener->*m_pfnSelector)(this); } } m_pText->setColor(m_normalLabelColor); }
bool Areas::onTouchBegan(Touch* touch, Event* event) { auto target = static_cast<Sprite*>(event->getCurrentTarget());//获取当前的触摸目标 Point locationInNode = target->convertToNodeSpace(touch->getLocation());//将本地坐标系转化为精灵坐标系(以精灵的左下角作为坐标原点) Size s = target->getContentSize();//获取精灵的文本尺寸大小 Rect rect = Rect(0, 0, s.width, s.height);//获取精灵的矩形框(起始点为精灵的左下角) if (rect.containsPoint(locationInNode))//判断触摸点是否在精灵的矩形框上 { log("Areas::onTouchBegan,%d", target->getTag()); } return true; }
void OrgRankList::ccTouchMoved(CCTouch* touch, CCEvent* event) { CCPoint touchLocation = touch->locationInView( touch->view() ); touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation ); CCPoint pos = convertToNodeSpace( touchLocation ); m_lastYm = touchLocation.y - last_moveTouch.y; last_moveTouch = touchLocation; float fOffsetY = pos.y - m_ptStartNode.y; CCPoint thisPt = this->getPosition(); thisPt.y += fOffsetY; setPosition(thisPt); }
void CCSpriteButton::ccTouchMoved(CCTouch *touch, CCEvent *event) { float distance=m_StartTouchPoint.getDistance(convertToNodeSpace(touch->getLocation())); if(abs(distance)<TOUCH_SENSITIVITY) //ÅжÏÊÇ·ñ³¬¹ýÁËÒƶ¯·¶Î§ { m_IsEmitTouchEvent=true; } else { m_IsEmitTouchEvent=false; } }
//触摸:开始 bool CNFServerChangeScrollLayer::onTouchBegan(Touch *pTouch, Event *pEvent) { Vec2 ptTouchPoint =pTouch->getLocation(); //设置初始触摸点 m_fTouchPassPosX = ptTouchPoint.x; m_fTouchBeginPosX = ptTouchPoint.x; //判断是否触摸到裁切区域内 if(m_DisPlayRect.containsPoint(ptTouchPoint)) { m_bTouching = true; //判断是否触摸到按钮 // Menu *pMenu = dynamic_cast<Menu*>(getChildByTag(enTagMenu)); auto pMenu = static_cast<Menu*>(getChildByTag(enTagMenu)); Vector<Node*> pChildren = pMenu->getChildren(); if(pMenu!=NULL) { int i=0; for(const auto &pItem : pChildren) { auto pBtn= static_cast<MenuItemSprite*>(pItem); if(pBtn!=NULL) { Vec2 local = pBtn->convertToNodeSpace(pTouch->getLocation()); Rect r = pBtn->rect(); r.origin = Vec2::ZERO; if (r.containsPoint(local)) { pMenu->onTouchBegan(pTouch,pEvent); m_bIsTouchBtn=true; } } i++; } } return true; } return false; }