NS_CC_BEGIN /** * 测试是否可以将物体限制在线段围成的区域里 */ bool LineBlockMap::checkCollide(const CCRect& rect) { CCPoint one = ccp(rect.origin.x,rect.origin.y); CCPoint two = ccp(rect.origin.x + rect.size.width,rect.origin.y); CCPoint three = ccp(rect.origin.x,rect.origin.y + rect.size.height); CCPoint four = ccp(rect.origin.x + rect.size.width,rect.origin.y + rect.size.height); std::vector<Line> locs; locs.resize(4); locs[0] = Line(one,two); locs[1] = Line(one,three); locs[2] = Line(three,four); locs[3] = Line(two,four); for (int i = 0; i < 4;i++) { Line &src = locs[i]; for (std::vector<Line>::iterator iter = _lines.begin(); iter != _lines.end(); ++iter) { Line &dest = *iter; if (rect.containsPoint(dest.src) || rect.containsPoint(dest.dest)) { return true; } if (LineCollide::checkCollide(src,dest)) { return true; } } } return false; }
bool GiftListView::ccTouchBegan( CCTouch *pTouch, CCEvent *pEvent ) { CCRect listRect = CCRectMake(0,0,getContentSize().width,getContentSize().height); if (listRect.containsPoint(convertTouchToNodeSpace(pTouch))) { //CCLOG("touch begin-------"); CCPoint locationPoint = pTouch->getLocation(); mMoveBeginPoint.setPoint(locationPoint.x,locationPoint.y); schedule(schedule_selector(GiftListView::touchUpdate)); for (int i=0;i<(int)mPages.count();i++) ((CCLayer*)mPages.objectAtIndex(i))->stopActionByTag(999); CCPoint touchPoint = convertTouchToNodeSpace(pTouch); int startIndex = (mPageCurr-1)*mPageSize; int endIndex = mGiftItems.count(); for (int i=startIndex;i<endIndex;i++) { GiftItem* item =(GiftItem*)mGiftItems.objectAtIndex(i); CCRect itemRect = CCRectMake(item->getPositionX(),item->getPositionY(),item->getContentSize().width,item->getContentSize().height); if(itemRect.containsPoint(touchPoint)) { item->setStatus(GiftItem::seled); mNowSeledItem = item; CCLOG("begin"); break; } } return true; } return false; }
bool Pause::ccTouchBegan(CCTouch* pTouch, CCEvent* pEvent) { CCPoint location = pTouch->getLocation(); CCRect* pHomeTextureRect = new CCRect(63, 25, 76.8, 32); CCRect* pGameTextureRect = new CCRect(200, 25, 76.8, 32); CCRect* pRestartTextureRect = new CCRect(339, 25, 76.8, 32); if (pHomeTextureRect->containsPoint(location)) { this->removeFromParentAndCleanup(true); CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("main.mp3", true); CCScene* pMainMenuScene = MainMenuScene::scene(); CCDirector::sharedDirector()->replaceScene(pMainMenuScene); CCDirector::sharedDirector()->resume(); CCLOG("Remove"); } else if (pGameTextureRect->containsPoint(location)) { this->removeFromParentAndCleanup(true); CCDirector::sharedDirector()->resume(); CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); CCLOG("Resume"); } else if (pRestartTextureRect->containsPoint(location)) { // this->dialog->setVisible(true); CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(true); CCScene* pGameScene = NormalGameScene::scene(); CCDirector::sharedDirector()->replaceScene(pGameScene); CCDirector::sharedDirector()->resume(); CCLOG("Restart"); } else if (this->dialog->isVisible()) { this->dialog->setVisible(false); } return true; }
void HelloWorld::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) { for(CCSetIterator it = pTouches->begin(); it != pTouches->end(); it++) { CCTouch* touch = (CCTouch*)(*it); if(touch == NULL) break; CCDirector* director = CCDirector::sharedDirector(); CCPoint p = touch->getLocationInView(); CCPoint touchPosition = director->convertToGL(p); CCSize size = m_rightItem->getContentSize(); CCPoint position = m_rightItem->getPosition(); CCRect rect = CCRectMake(position.x - size.width/2, position.y - size.height/2, size.width, size.height); m_isPressedRight = rect.containsPoint(touchPosition); if(!m_isPressedRight) { CCSize size = m_leftItem->getContentSize(); CCPoint position = m_leftItem->getPosition(); CCRect rect = CCRectMake(position.x - size.width/2, position.y - size.height/2, size.width, size.height); m_isPressedLeft = rect.containsPoint(touchPosition); } } //m_isPressedLeft = m_leftItem->co }
bool CATextSelViewEx::ccTouchBegan(CATouch *pTouch, CAEvent *pEvent) { CCPoint cTouchPoint = this->convertTouchToNodeSpace(pTouch); CCRect newRectL = m_pCursorMarkL->getFrame(); newRectL.InflateRect(8); CCRect newRectR = m_pCursorMarkR->getFrame(); newRectR.InflateRect(8); m_iSelViewTouchPos = 0; if (newRectL.containsPoint(cTouchPoint)) { m_iSelViewTouchPos = 1; } else if (newRectR.containsPoint(cTouchPoint)) { m_iSelViewTouchPos = 2; } else if (m_pControlView) { if (touchSelectText(pTouch)) { CATextToolBarView *pToolBar = CATextToolBarView::create(); pToolBar->addButton(UTF8("\u526a\u5207"), m_pControlView, callfunc_selector(CATextView::ccCutToClipboard)); pToolBar->addButton(UTF8("\u590d\u5236"), m_pControlView, callfunc_selector(CATextView::ccCopyToClipboard)); pToolBar->addButton(UTF8("\u7c98\u8d34"), m_pControlView, callfunc_selector(CATextView::ccPasteFromClipboard)); pToolBar->show(m_pControlView); return false; } } return true; }
bool Player::ccTouchBegan(CCTouch* touch, CCEvent* event) { CCPoint point = this->convertTouchToNodeSpace(touch); const CCSize& size = getContentSize(); CCRect box = m_sprite->boundingBox(); int containtit = box.containsPoint(point); return box.containsPoint(point); }
CCMenuItem* MyMenu::itemForTouch(CCTouch *touch) { CCPoint touchLocation = touch->getLocationInView(); touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation); if (m_pChildren && m_pChildren->count() > 0) { CCObject* pObject = NULL; CCARRAY_FOREACH(m_pChildren, pObject) { CCMenuItem* pChild = dynamic_cast<CCMenuItem*>(pObject); if (pChild && pChild->isVisible() && ((CCMenuItem*)pChild)->isEnabled()) { if (dynamic_cast<MyTiledMenuItemSprite*>(pChild) != NULL){ CCPoint posiT = map->transMapToTiled(this->getPosition()); CCPoint tiled = map->transMapToTiled(map->convertToNodeSpace(touchLocation)); if (contentSizeByTiled.width == 1 && contentSizeByTiled.height == 1) { CCPoint local = pChild->convertToNodeSpace(touchLocation); CCRect r = ((CCMenuItem*)pChild)->rect(); r.origin = CCPointZero; if (r.containsPoint(local)) { //物体碰撞系统参数,上面是地形碰撞系统 // ((MyMap*)map)->initTip(this->getPosition(), contentSizeByTiled.width); // ((MyMap*)map)->cancelAllBuilding(); // ((MyMap*)map)->moveTemp = this; cacheLoc = this->getPosition(); return (CCMenuItem*)pChild; } } else { if(Mathlib::inBound(tiled.x, posiT.x+contentSizeByTiled.width/2, posiT.x-contentSizeByTiled.width/2) && Mathlib::inBound(tiled.y, posiT.y+contentSizeByTiled.height/2, posiT.y-contentSizeByTiled.height/2)) { cacheLoc = this->getPosition(); // ((MyMap*)map)->initTip(this->getPosition(), contentSizeByTiled.width); // ((MyMap*)map)->cancelAllBuilding(); // ((MyMap*)map)->moveTemp = this; return (CCMenuItem*)pChild; } } } else { CCPoint local = pChild->convertToNodeSpace(touchLocation); CCRect r = ((CCMenuItem*)pChild)->rect(); r.origin = CCPointZero; if (r.containsPoint(local)) { //物体碰撞系统参数,上面是地形碰撞系统 //TODO // ((MyMap*)map)->moveTemp = this; cacheLoc = this->getPosition(); return (CCMenuItem*)pChild; } } } }
void LevelScene::ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) { CCTouch *pTouch = (CCTouch*)pTouches->anyObject(); CCPoint touchLocation = pTouch->getLocationInView(); touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation); CCPoint local = convertToNodeSpace(touchLocation); /*for (CCSetIterator iterTouch = pTouches->begin(); iterTouch != pTouches->end(); iterTouch++) { CCTouch *pcurTouch = (CCTouch*)(*iterTouch); CCPoint pcurPoint = pcurTouch->getLocationInView(); pcurPoint = CCDirector::sharedDirector()->convertToGL(pcurPoint); CCPoint curLoc = convertToNodeSpace(pcurPoint); }*/ CCArray* childArr = getChildren(); for (int i=0; i<getChildrenCount(); i++) { CCSprite *sprite = (CCSprite*)childArr->objectAtIndex(i); if (sprite->getTag() <= 0 ) continue; CCRect spriteRect = sprite->boundingBox(); // back if (sprite->getTag() == kTagback && spriteRect.containsPoint(local)) { sprite->setColor(ccc3(222, 43, 54)); SimpleAudioEngine::sharedEngine()->playEffect("button_press.wav"); CCScene *pScene = StartScene::scene(); CCDirector::sharedDirector()->replaceScene(CCTransitionSplitRows::create(1, pScene)); return; } // map no if (spriteRect.containsPoint(local)) { sprite->setColor(ccc3(222, 43, 54)); SimpleAudioEngine::sharedEngine()->playEffect("button_press.wav"); CCDirector::sharedDirector()->replaceScene(CCTransitionSplitRows::create(1, GameScene::sceneWithMap(sprite->getTag()))); return; } } // back button /*CCRect rect1 = _backSprite->boundingBox(); bool flag = rect1.containsPoint(local); if (flag) { CCScene *pScene = StartScene::scene(); CCDirector::sharedDirector()->replaceScene(CCTransitionSplitRows::create(1, pScene)); }*/ }
bool TapSprite::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { if(status->getAnimationFlg()) return false; // タッチ開始処理 // タッチ位置を取得 CCPoint point = pTouch->getLocation(); // スプライトの大きさ CCSize size = this->getTexture()->getContentSize(); // スプライトの範囲 CCRect rect = CCRectMake(this->getPositionX()-size.width/2, this->getPositionY()-size.height/2, size.width, size.height); // タッチ位置がスプライト内ならイベント処理するのでtrueを返す if(rect.containsPoint(point)){ status->setWaitFlg(false); status->setChangeFlg(false); CCNode* parent; CCSprite* sprite; sprite = status->getSprite(thisx,thisy); parent = sprite->getParent(); parent->removeChild(sprite); parent->addChild(sprite); //this->setPosition(point); this->setPosition(ccp(point.x,point.y + 25)); return true; }else{ return false; } }
bool HelloWorld::canBuildOnTilePosition(CCPoint pos) { // pos=ccpAdd(pos, ccp(0, 50)); CCPoint towerLoc = tileCoordForPosition(pos); int tileGid =_background->tileGIDAt(towerLoc); CCDictionary *props = _tileMap->propertiesForGID(tileGid); const CCString *type = props->valueForKey("buildable"); CCString* str=CCString::create("1"); DataModel *m = DataModel::getModel(); bool occupied = false; for (int i=0;i< m->getTowers()->count();i++) { Towers *tower=(Towers*)m->getTowers()->objectAtIndex(i); CCRect towerRect = CCRectMake(tower->getPosition().x - (tower->getContentSize().width/2), tower->getPosition().y - (tower->getContentSize().height/2), tower->getContentSize().width, tower->getContentSize().height); if (towerRect.containsPoint(pos)) { occupied = true; } } if(str->isEqual(type)&&!occupied) { return true; } return false; }
void DragLayer::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) { //CCLOG("Drag move"); if (m_isDraging) { CCNode *element = getChildByTag(kDragElementTag); if (element) { CCPoint touchLocation = pTouch->getLocationInView(); touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation); element->setPosition(touchLocation); CCRect rect = CCRectMake(element->getPosition().x - element->getContentSize().width * 0.5f, element->getPosition().y - element->getContentSize().height * 0.5f, element->getContentSize().width, element->getContentSize().height); // 先测试一个筐的粘滞效果 if (rect.containsPoint(m_destinationLayer->getPosition())) { CCLOG("开始粘滞"); CCSprite *spr = CCSprite::create("Icon.png"); spr->setDisplayFrame(((CCSprite *)element)->displayFrame()); spr->setPosition(element->getPosition()); addChild(spr); //播放粘滞动画 CCMoveTo *returnToStartPosition = CCMoveTo::create(0.3f, m_destinationLayer->getPosition()); CCEaseExponentialOut *exponent = CCEaseExponentialOut::create(returnToStartPosition); //执行函数 //CCCallFuncN *call = CCCallFuncN::actionWithTarget(this, callfuncN_selector(DragLayer::removeElement)); CCAction *sequence = CCSequence::create(exponent, NULL); spr->runAction(sequence); removeElement(); } } } }
bool WHScrollView::onTouchBegan(cocos2d::Touch *pTouch, cocos2d::Event *pEvent) { CCPoint localPoint = convertTouchToNodeSpace(pTouch); CCRect rect = CCRectMake(0, 0, _viewSize.width, _viewSize.height); if (!rect.containsPoint(localPoint)) return false; if (!ScrollView::onTouchBegan(pTouch, pEvent)) return false; if (m_PointerId != -1) return false; m_BeginPoint = localPoint; m_PointerId = pTouch->getID(); //CCScrollView::ccTouchBegan(pTouch, pEvent); m_MoveCount = 1; for (int i = 0; i < m_TouchLayer.size(); i++) { CCLayer* pTouchLayer = m_TouchLayer[i]; m_TouchLayerTouched[i] = pTouchLayer->onTouchBegan(pTouch, pEvent); if (m_TouchLayerTouched[i]) break; } return true; }
//¶ÔÏóÊÇ·ñ±»´¥Ãþ //bool BaseObject::containsTouchLocation(cocos2d::CCTouch *touch) bool BaseObject::containsTouchLocation(CCPoint world_point) { CCSize size = getSprite()->getContentSize(); CCRect rect = CCRect(-size.width / 2.0, -size.height / 2.0, size.width, size.height); //return rect.containsPoint(convertTouchToNodeSpaceAR(touch)); return rect.containsPoint(convertToNodeSpaceAR(world_point)); }
void TargetLayer::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) { CCLog("Game State : %d", ((GameScene*)this->getParent())->gameState); if ((((GameScene*)this->getParent())->gameState == GAME_ANNOUNCE_LETTER) || ((GameScene*)this->getParent())->gameState == GAME_HIDE) { CCTouch* fingerOne = (CCTouch*)pTouches->anyObject(); CCPoint pointOne = CCDirector::sharedDirector()->convertToUI(fingerOne->getLocationInView()); CCPoint location = this->convertToNodeSpace(pointOne); for (int index = 0; index < targets->count(); index++) { CCSprite* target = (CCSprite*)targets->objectAtIndex(index); // Get the Box of the sprite CCRect rect = target->boundingBox(); if (rect.containsPoint(location)) { if (((GameScene*)this->getParent())->gameState == GAME_HIDE) { this->showLetters(); } CCLog("Shooted %d", index); this->doShoot(target); break; } } } }
bool LeaderBoardAdvanceModeNode::onTouchCustomNodeBegan(Touch* pTouch, Event* pEvent) { if (m_iLeaderBoardCount > 3) { Point touchPosition = pTouch->getLocation(); m_fBeginX = touchPosition.x; CCRect *pRectButton = new CCRect(m_pSpriteBackground->getOffsetPosition().x, m_pSpriteBackground->getOffsetPosition().y, m_pSpriteBackground->getTextureRect().size.width, m_pSpriteBackground->getTextureRect().size.height); Point touchButton = m_pSpriteBackground->convertToNodeSpace(touchPosition); if(pRectButton->containsPoint(touchButton)) { DataTouch dataTouch; dataTouch.point = touchPosition; dataTouch.lTime = 0; dataTouch.fDeltaTime = 0; m_pScrollManager->addDataToQueue(dataTouch); return true; } } return false; }
void ArenaFindPlayer::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent) { CCPoint endPos = pTouch->getLocation(); float delta = 5.0f; if (::abs(endPos.x - m_beginPos.x) > delta || ::abs(endPos.y - m_beginPos.y) > delta) { // not click m_beginPos.x = m_beginPos.y = -1; return; } // decide the trackNode is clicked. CCPoint point = convertTouchToNodeSpace(pTouch); CCRect rect; rect.origin = m_InputPlayerName->getPosition(); rect.size = m_InputPlayerName->getDimensions(); rect.origin.x -= m_InputPlayerName->getAnchorPointInPoints().x; rect.origin.y -= m_InputPlayerName->getAnchorPointInPoints().y; if (rect.containsPoint(point)) { m_InputPlayerName->attachWithIME(); } else { m_InputPlayerName->detachWithIME(); } }
void GameScene::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){ CCDirector* pDirector = CCDirector::sharedDirector(); CCPoint touchPoint = pDirector->convertToGL(pTouch->getLocationInView()); CCNode* pCard = this->getChildByTag(nextNumber); if (!pCard) { return; } CCRect cardRect = pCard->boundingBox(); if (cardRect.containsPoint(touchPoint)) { CCSprite* pNewCard = CCSprite::create("card_backside.png"); pNewCard->setPosition(pCard->getPosition()); this->addChild(pNewCard); pCard->removeFromParentAndCleanup(true); if (nextNumber >= 25) { this->unschedule(schedule_selector(GameScene::measureGametime)); showHighScoreLabel(); return; } nextNumber++; } //CCLog("x: %f, y:%f", touchPoint.x, touchPoint.y); }
/** * 停止拖动 */ bool UILabel::touchEnd(float x,float y) { if (_editable && _touchIn) { this->doEvent(UIBase::EVENT_EDIT_DOWN,this); } _touchIn = false; if (_editable) return false; CCPoint pos = ccp(x,y); pos = this->convertToNodeSpace(pos); if (text) { CCRect rect = CCRectMake( text->getPosition().x - (text->getContentSize().width/2), text->getPosition().y - (text->getContentSize().height/2), text->getContentSize().width, text->getContentSize().height); if (rect.containsPoint(pos)) { // 触发事件 doEvent(UIBase::EVENT_CLICK_DOWN,this); } } return true; }
int ai_getMapRectNumberOf(Character *c, I8MapRectsOperational* eightMapInstance) { CCAssert(eightMapInstance != NULL, "Check if eightMapInstance is not null"); // get vector of 8 map-rects std::vector<CCRect> mapRects = eightMapInstance->get8MapRects(); // get character's position CCPoint cPos = c->getPosition(); // take into account the y-anchor point // for some characters esp if they're tall, their position might appear above the limit position // this prevents below CCAssert() to pass cPos.y -= c->getStaticCollisionSize().height * c->getAnchorPoint().y; // loop through all the map-rects then for(int i=0; i<mapRects.size(); i++) { // get the map rect CCRect rect = mapRects[i]; // check if position is in the current rectangle or not if(rect.containsPoint(cPos)) { return i+1; } } CCAssert(false, "Map rect position must be found."); }
/** * 检查是否在区域里 */ bool UITextButton::touchDown(float x,float y) { CCPoint pos = ccp(x,y); _touchIn = false; pos = this->convertToNodeSpace(pos); nowTouchPoint = ccp(x,y); if (_textUp && _textDown) { float width = _textUp->getContentSize().width * _textUp->getScaleX(); float height = _textUp->getContentSize().height * _textUp->getScaleY(); CCRect rect = CCRectMake( _textUp->getPosition().x - (width/2), _textUp->getPosition().y - (height/2), width, height); if (rect.containsPoint(pos)) { if (!_editable) { _textUp->setVisible(false); _textDown->setVisible(true); } _touchIn = true; return true; } } return false; }
/** * 更新位置 */ bool UIButton::touchMove(float x,float y) { CCPoint pos = ccp(x,y); if (_editable && _touchIn) { CCPoint nowPoint = getPosition(); setPosition(nowPoint.x + pos.x - nowTouchPoint.x, nowPoint.y + pos.y - nowTouchPoint.y); nowTouchPoint = pos; return true; } if (_up && _down) { CCRect rect = CCRectMake( _up->getPosition().x - (_up->getContentSize().width/2), _up->getPosition().y - (_up->getContentSize().height/2), _up->getContentSize().width, _up->getContentSize().height); if (rect.containsPoint(pos)) { if (_move) { _up->setVisible(false); _down->setVisible(false); _move->setVisible(true); } } } return false; }
void GameLayer::ccTouchesBegan(CCSet* touches, CCEvent* event) { CCTouch *touch = (CCTouch *)touches->anyObject(); if (touch) { CCPoint tap = touch->getLocation(); CCRect boundary; //handle button touches CCSprite * button; CCSprite * buttonPress; for (int i = 0; i < 5; i++) { button = (CCSprite *) _buttons->objectAtIndex(i); if (!button->isVisible()) continue; boundary = button->boundingBox(); if (boundary.containsPoint(tap)) { buttonPress = (CCSprite *) button->getChildByTag(kSpriteBtnOn); buttonPress->setVisible(true); return; } } } }
///重写当触摸释放时调用 void CTableView::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) { if (!this->isVisible()) { return; } if (m_pTouchedCell){ CCRect bb = this->boundingBox(); bb.origin = m_pParent->convertToWorldSpace(bb.origin); if (bb.containsPoint(pTouch->getLocation())) { if (m_pTableViewDelegate != NULL) { m_pTableViewDelegate->tableCellUnhighlight(this, m_pTouchedCell); } //让菜单处理事件 bool bIsActivate = ((CTableViewCell*)m_pTouchedCell)->activate(); //如果没有菜单项处理事件,就把事件交给代理 if (m_pTableViewDelegate != NULL && !bIsActivate) { m_pTableViewDelegate->tableCellTouched(this, m_pTouchedCell); } } m_pTouchedCell = NULL; } CCScrollView::ccTouchEnded(pTouch, pEvent); //自动对齐到页 this->adjust(); }
bool GetAwardLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { CCPoint touchLocation = pTouch->getLocation(); CCPoint pos = mBoard->convertToNodeSpace(touchLocation); CCRect rect = mBoard->getTextureRect(); rect.origin = CCPointZero; if (rect.containsPoint(pos)) { mBoard->runAction(CCSequence::create( CCScaleTo::create(0.1f,1.1f), CCScaleTo::create(0.1f,0.9f), CCScaleTo::create(0.05f,1.0f), NULL )); return true; } this->runAction(CCSequence::create( CCScaleTo::create(0.1f, 0.1f), CCRemoveSelf::create(), NULL)); return true; }
/** * 停止拖动 */ bool UITextButton::touchEnd(float x,float y) { if (_editable && _touchIn) { this->doEvent(UIBase::EVENT_EDIT_DOWN,this); } _touchIn = false; if (_editable) return false; CCPoint pos = ccp(x,y); pos = this->convertToNodeSpace(pos); if (_textDown && _textUp) { float width = _textUp->getContentSize().width * _textUp->getScaleX(); float height = _textUp->getContentSize().height * _textUp->getScaleY(); CCRect rect = CCRectMake( _textUp->getPosition().x - (width/2), _textUp->getPosition().y - (_textUp->getContentSize().height/2), width, height); _textUp->setVisible(true); _textDown->setVisible(false); if (rect.containsPoint(pos)) { // 触发事件 doEvent(UIBase::EVENT_CLICK_DOWN,this); } } return true; }
bool UIWepon::ccTouchBegan( CCTouch* pTouch, CCEvent* event ) { CCPoint touchPosition = pTouch->getLocation(); // 选择宝石 for (int i = 0; i < 4; i++) { CCPoint position = gemImageView[i]->getPosition(); CCSize size = gemImageView[i]->getContentSize(); CCRect rect = CCRect(position.x-size.width/2, position.y-size.height/2, size.width, size.height); if (rect.containsPoint(touchPosition)) { weponManager->selectGemId = weponManager->pageNum * 4 + i; selectGemSprite = weponManager->gemSpriteArray[i]; weponManager->gemSpriteArray[i].sprite = NULL; weponManager->gemSpriteArray[i].weponGem.gem = NULL; return true; } } CCLOG("ccTouchBegan"); return true; }
bool Background::judgeUseBomb(CCPoint tapPoint) { CCLOG("Judge pause intersect"); if(totalBomb==0) return false; CCRect rect = CCRectMake(bombPoint->getPointX()-bombPoint->getSize()->getWidth()/2, bombPoint->getPointY()-bombPoint->getSize()->getHeight()/2, bombPoint->getSize()->getWidth(), bombPoint->getSize()->getHeight()); return rect.containsPoint(tapPoint); }
/** * 检查是否在区域里 */ bool UIButton::touchDown(float x,float y) { CCPoint pos = ccp(x,y); _touchIn = false; pos = this->convertToNodeSpace(pos); nowTouchPoint = ccp(x,y); if (_up && _down) { CCRect rect = CCRectMake( _up->getPosition().x - (_up->getContentSize().width/2), _up->getPosition().y - (_up->getContentSize().height/2), _up->getContentSize().width, _up->getContentSize().height); if (rect.containsPoint(pos)) { if (!_editable) { _up->setVisible(false); _down->setVisible(true); if (_move) { _move->setVisible(false); } } _touchIn = true; return true; } } return false; }
void KeyboardNotificationLayer::ccTouchended(CCTouch *pTouch, CCEvent *pEvent) { if (! m_pTrackNode) { return; } CCPoint endPos = pTouch->getLocation(); float delta = 5.0f; if (::abs(endPos.x - m_beginPos.x) > delta || ::abs(endPos.y - m_beginPos.y) > delta) { // not click m_beginPos.x = m_beginPos.y = -1; return; } // decide the trackNode is clicked. CCRect rect; CCPoint point = convertTouchToNodeSpaceAR(pTouch); CCLOG("KeyboardNotificationLayer:clickedAt(%f,%f)", point.x, point.y); rect = getRect(m_pTrackNode); CCLOG("KeyboardNotificationLayer:TrackNode at(origin:%f,%f, size:%f,%f)", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); this->onClickTrackNode(rect.containsPoint(point)); CCLOG("----------------------------------"); }
bool BaseBug::containsTouchLocation(cocos2d::CCTouch * pTouch){ CC_ASSERT(m_bug); CCSize s = m_bug->getContentSize(); CCRect rect = CCRectMake(-s.width/2, -s.height/2, s.width, s.height); CCPoint nodePoint = convertTouchToNodeSpaceAR(pTouch); return rect.containsPoint(nodePoint); }