本文整理汇总了C++中CCRect::containsPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ CCRect::containsPoint方法的具体用法?C++ CCRect::containsPoint怎么用?C++ CCRect::containsPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCRect
的用法示例。
在下文中一共展示了CCRect::containsPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkCollide
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;
}
示例2: ccTouchBegan
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;
}
示例3: ccTouchBegan
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;
}
示例4: ccTouchesBegan
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
}
示例5: ccTouchBegan
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;
}
示例6: ccTouchBegan
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);
}
示例7: itemForTouch
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;
}
}
}
}
示例8: ccTouchesEnded
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));
}*/
}
示例9: ccTouchBegan
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;
}
}
示例10: canBuildOnTilePosition
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;
}
示例11: ccTouchMoved
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();
}
}
}
}
示例12: onTouchBegan
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;
}
示例13: containsTouchLocation
//¶ÔÏóÊÇ·ñ±»´¥Ãþ
//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));
}
示例14: ccTouchesBegan
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;
}
}
}
}
示例15: ccTouchEnded
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();
}
}