本文整理汇总了C++中CCRect::intersectsRect方法的典型用法代码示例。如果您正苦于以下问题:C++ CCRect::intersectsRect方法的具体用法?C++ CCRect::intersectsRect怎么用?C++ CCRect::intersectsRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCRect
的用法示例。
在下文中一共展示了CCRect::intersectsRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkCollision
void HoldOnGame::checkCollision(){
//小球与障碍物
CCRect ballRect = playerBall->boundingBox();
CCRect rect = CCRect(ballRect.origin.x + KBallOffset, ballRect.origin.y + KBallOffset,
ballRect.size.width - KBallOffset * 2, ballRect.size.height - KBallOffset * 2);
for (int i = KBodyTypeRectangleVer; i <= KBodyTypeSquare; i++) {
CCSprite* sprite = (CCSprite*)gameLayer->getChildByTag(i);
if (rect.intersectsRect(sprite->boundingBox())) {
bool over = true;
if (sprite->getTag() == KBodyTypeTriangle) {
CCRect sRect = sprite->boundingBox();
CCRect rect1 = CCRect(sRect.origin.x + (sRect.size.width * 0.25) / 2 + KBallOffset, sRect.origin.y,
sRect.size.width * 0.75 - KBallOffset * 2, sRect.size.height * 0.25);
if (!rect.intersectsRect(rect1)) {
rect1 = CCRect(sRect.origin.x + sRect.size.width * 0.25 + KBallOffset, sRect.origin.y + sRect.size.height * 0.25,
sRect.size.width * 0.5 - KBallOffset * 2, sRect.size.height * 0.25);
if (!rect.intersectsRect(rect1)) {
rect1 = CCRect(sRect.origin.x + sRect.size.width * 3 / 8 + KBallOffset, sRect.origin.y + sRect.size.height * 0.5,
sRect.size.width * 0.25 - KBallOffset* 2, sRect.size.height * 0.25);
if (!rect.intersectsRect(rect1)) {
rect1 = CCRect(sRect.origin.x + sRect.size.width * 0.45, sRect.origin.y + sRect.size.height * 0.75,
sRect.size.width * 0.1, sRect.size.height * 0.15);
if (!rect.intersectsRect(rect1)) {
over = false;
} else {
CCLOG("44444 rect1 = (%.1f, %.1f, %.1f, %.1f)", rect1.origin.x, rect1.origin.y, rect1.size.width, rect1.size.height);
}
} else {
CCLOG("333333 rect1 = (%.1f, %.1f, %.1f, %.1f)", rect1.origin.x, rect1.origin.y, rect1.size.width, rect1.size.height);
}
} else {
CCLOG("22222222 rect1 = (%.1f, %.1f, %.1f, %.1f)", rect1.origin.x, rect1.origin.y, rect1.size.width, rect1.size.height);
}
} else {
CCLOG("1111111 rect1 = (%.1f, %.1f, %.1f, %.1f)", rect1.origin.x, rect1.origin.y, rect1.size.width, rect1.size.height);
}
// if (over) {
// CCLOG("rect = (%.1f, %.1f, %.1f, %.1f)", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
// CCLOG("sRect = (%.1f, %.1f, %.1f, %.1f)", sRect.origin.x, sRect.origin.y, sRect.size.width, sRect.size.height);
// CCLOG("game over");
//// this->gameOver();
// break;
// }
}
if (over) {
this->gameOver();
break;
}
}
}
}
示例2: handleUserTouch
void HelloWorld::handleUserTouch(CCTouch *touch)
{
CCSprite *pArrow= (CCSprite*)getChildByTag(kArrow);
CCPoint location = touch->getLocation();
location = CCDirector::sharedDirector()->convertToGL(location);
float x =(float) location.x;
float y =(float) location.y;
CCSprite *pImage2= (CCSprite*)getChildByTag(kTop);
CCSprite *pImage1= (CCSprite*)getChildByTag(kRight);
CCSprite *pImage3= (CCSprite*)getChildByTag(kBot);
CCSprite *pImage4= (CCSprite*)getChildByTag(kLeft);
CCRect topRect = CCRectMake(pImage2->getPosition().x,pImage2->getPosition().y,50,50);
CCRect rightRect = CCRectMake(pImage1->getPositionX(),pImage1->getPositionY(),50,50);
CCRect botRect = CCRectMake(pImage3->getPositionX(),pImage3->getPositionY(),50,50);
CCRect leftRect = CCRectMake(pImage4->getPositionX(),pImage4->getPositionY(),50,50);
CCRect pointRect = CCRectMake(x,y,50,50);
if(topRect.intersectsRect(pointRect))
{
pArrow->setPositionX(pArrow->getPositionX());
pArrow->setPositionX(pArrow->getPositionY()+10);
}
else if
(rightRect.intersectsRect(pointRect))
{
pArrow->setPositionX(pArrow->getPositionX()+10);
pArrow->setPositionX(pArrow->getPositionY());
}
else if
(botRect.intersectsRect(pointRect))
{
pArrow->setPositionX(pArrow->getPositionX());
pArrow->setPositionX(pArrow->getPositionY()-10);
}
else if
(leftRect.intersectsRect(pointRect))
{
pArrow->setPositionX(pArrow->getPositionX()-10);
pArrow->setPositionX(pArrow->getPositionY());
}
}
示例3: updateGame
void HelloWorld::updateGame(float dt)
{
// given the current Player's Rect, check collisions with all targets falling on the screen
CCSize playerSize = m_player->getContentSize();
CCPoint playerPosition = m_player->getPosition();
CCRect playerRect = CCRectMake(playerPosition.x - playerSize.width/2, playerPosition.y - playerSize.height / 2, playerSize.width, playerSize.height);
CCArray* targetsToDelete =new CCArray;
CCObject* jt = NULL;
CCARRAY_FOREACH(m_targets, jt)
{
CCSprite *target = dynamic_cast<CCSprite*>(jt);
CCRect targetRect = CCRectMake(
target->getPosition().x - (target->getContentSize().width/2),
target->getPosition().y - (target->getContentSize().height/2),
target->getContentSize().width,
target->getContentSize().height);
// if (CCRect::CCRectIntersectsRect(projectileRect, targetRect))
if (playerRect.intersectsRect(targetRect))
{
// collision here...
targetsToDelete->addObject(target);
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("splash.mp3");
}
}
示例4: touchMoved
KDvoid JewelController::touchMoved ( APSGraphic* pGraphic, const APSTouch& tTouch )
{
// calculate touched position in symbol
CCPoint tPosition = m_pSymbol->convertPositionFromParentNode ( tTouch.getPosition ( ) );
CCNode* pJewelNode = pGraphic->getNode ( );
// change jewel graphic node position to touched position.
pJewelNode->setPosition ( tPosition );
// get the rectangular box of jewel node
CCRect tJewelBox = pJewelNode->boundingBox ( );
// get the rectangular box of boy node.
CCRect tBoyBox = m_pBoyGraphic->getNode ( )->boundingBox ( );
// check intersection of the two boxes.
if ( tJewelBox.intersectsRect ( tBoyBox ) )
{
APSActionGroup* pShakeBoyAction = (APSActionGroup*) m_pSymbol->getResourceForTag ( "ShakeBoy" );
// trigger 'ShakeBoy' action group only if it is currently not running.
if ( !pShakeBoyAction->getRunning ( ) )
{
pShakeBoyAction->trigger ( );
}
}
}
示例5: keyboardWillShow
void CCEditBox::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
{
// CCLOG("CCEditBox::keyboardWillShow");
CCRect rectTracked = getRect(this);
//postion bug fix code -sunxy
if (m_pParent != NULL)
{
rectTracked.origin = m_pParent->convertToWorldSpace(rectTracked.origin);
}
// if the keyboard area doesn't intersect with the tracking node area, nothing needs to be done.
if (!rectTracked.intersectsRect(info.end))
{
CCLOG("needn't to adjust view layout.");
return;
}
// assume keyboard at the bottom of screen, calculate the vertical adjustment.
m_fAdjustHeight = info.end.getMaxY() - rectTracked.getMinY();
// CCLOG("CCEditBox:needAdjustVerticalPosition(%f)", m_fAdjustHeight);
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->doAnimationWhenKeyboardMove(info.duration, m_fAdjustHeight);
}
}
示例6: update
void CATableView::update(float fDelta)
{
CAScrollView::update(fDelta);
CCRect rect = this->getBounds();
rect.origin.y -= rect.size.height * 0.1f;
rect.size.height *= 1.2f;
std::deque<CATableViewCell*>::iterator itr;
for (itr=m_pTableCells.begin(); itr!=m_pTableCells.end(); itr++)
{
CATableViewCell* cell = *itr;
CCRect cellRect = cell->getFrame();
cellRect.origin = m_pContainer->convertToWorldSpace(cellRect.origin);
cellRect.origin = this->convertToNodeSpace(cellRect.origin);
if (rect.intersectsRect(cellRect))
{
cell->setVisible(true);
}
else
{
cell->setVisible(false);
}
}
}
示例7: IsPutable
bool CBoxBehaviorState::IsPutable(CCSprite* sprite, CCPoint touchPos, CCPoint& avaliablePos)
{
auto arr = CObjectManager::getInstance()->getBox2dSprite();
CCPoint setPos;
bool bIsEnable = true;
CCRect rect;
for (int i = 0; i <= 20; i++)
{
for (int j = 0; j <= 20; j++)
{
CCRect r;
r.setRect(i * 105 + CScrollManager::getInstance()->getDeltaPosition().x, j * 105 + CScrollManager::getInstance()->getDeltaPosition().y, 105, 105);
if (r.containsPoint(touchPos))
{
setPos = ccp(r.getMidX(), r.getMidY());
rect = r;
}
}
}
for (int i = 0; i < arr->getSize(); i++)
{
auto anothersprite = arr->getObjectAt(i)->getSpritePtr();
if (rect.intersectsRect(anothersprite->getBoundingBox()))
bIsEnable = false;
}
avaliablePos = setPos;
return bIsEnable;
}
示例8: update
void LCBattleScene::update(float duration){
tree->clear();
for(int i = 0; i < monsterArr->count(); ++i){
tree->addObject((ObjMonster*)monsterArr->objectAtIndex(i));
}
tree->addObject(hero);
CCArray* arr = CCArray::create();
for(int i = 0; i < monsterArr->count(); ++i){
ObjMonster* monster = (ObjMonster*)monsterArr->objectAtIndex(i);
//if(monster->getrootObj() == NULL) continue;
tree->getCollisionObjects(monster, arr);
for(int j = 0; j < arr->count(); ++j){
ObjMonster* monster_1 = (ObjMonster*)arr->objectAtIndex(j);
CCRect rec = CCRectMake(monster->getShadow()->getPositionX(), monster->getShadow()->getPositionY(), monster->getShadow()->getContentSize().width, monster->getShadow()->getContentSize().height);
CCRect rec_1 = CCRectMake(monster_1->getShadow()->getPositionX(), monster_1->getShadow()->getPositionY(), monster_1->getShadow()->getContentSize().width, monster_1->getShadow()->getContentSize().height);
if(rec.intersectsRect(rec_1)){
//int flag = j % 2 == 0 ? 1 : -1;
monster_1->moveAway();//(ccp(flag * 20, flag * 20));
}
}
}
}
示例9: loadCollectionCell
void CACollectionView::loadCollectionCell()
{
CCRect rect = this->getBounds();
rect.origin = getContentOffset();
rect.origin.y -= rect.size.height * 0.1f;
rect.size.height *= 1.2f;
std::map<CAIndexPath3E, CACollectionViewCell*>::iterator itr;
for (itr = m_pUsedCollectionCells.begin(); itr != m_pUsedCollectionCells.end(); itr++)
{
CC_CONTINUE_IF(itr->second != NULL);
CAIndexPath3E r = itr->first;
CCRect cellRect = m_rUsedCollectionCellRects[r];
CC_CONTINUE_IF(!rect.intersectsRect(cellRect));
CACollectionViewCell* cell = m_pCollectionViewDataSource->collectionCellAtIndex(this, cellRect.size, r.section, r.row, r.item);
if (cell)
{
cell->m_nSection = r.section;
cell->m_nRow = r.row;
cell->m_nItem = r.item;
cell->updateDisplayedAlpha(this->getAlpha());
this->addSubview(cell);
cell->setFrame(cellRect);
itr->second = cell;
if (m_pSelectedCollectionCells.count(r))
{
cell->setControlStateSelected();
}
}
}
}
示例10: _ai_checkFullHit
NS_S_HARPENGINE
bool _ai_checkFullHit(harp::Character* base, harp::Character *against, float yLayerAttackRangeCheck, bool isMidAirCheck)
{
CCSize baseDynamicSize = base->getDynamicCollisionSize();
CCSize againstDynamicSize = against->getDynamicCollisionSize();
// check roughly first
if(((!isMidAirCheck && !against->isInMidAir()) || isMidAirCheck) &&
!against->isDead() &&
fabsf(against->getPositionX() - base->getPositionX()) <= baseDynamicSize.width*2 &&
fabsf(against->getPositionY() - base->getPositionY()) <= yLayerAttackRangeCheck)
{
// finer check
CCRect baseRect = CCRectMake(base->getPositionX() - baseDynamicSize.width*0.5f, base->getPositionY() - baseDynamicSize.height*0.5f, baseDynamicSize.width, baseDynamicSize.height);
CCRect againstRect = CCRectMake(against->getPositionX() - againstDynamicSize.width*0.5f, against->getPositionY() - againstDynamicSize.height*0.5f, againstDynamicSize.width, againstDynamicSize.height);
if(baseRect.intersectsRect(againstRect))
{
// collided!
return true;
}
else
{
// not collide
return false;
}
}
else
{
// not collide
return false;
}
}
示例11: getMaterialPosition
CCPoint Grass::getMaterialPosition(DungeonSpriteBase* parent)
{
int width = parent->getContentSize().width;
int height = parent->getContentSize().height;
CCPoint resultPoint;
while (true) {
int x = ShinzoUtil::getRandamRange((parent->getPosition().x) - (width * 3.0f / 2), (parent->getPosition().x) + (width * 3.0f / 2));
int y = ShinzoUtil::getRandamRange((parent->getPosition().y) - (height * 3.0f / 2), (parent->getPosition().y) + (height * 3.0f / 2));
CCPoint gracePoint = parent->convertToNodeSpace(ccp(x, y));
CCRect graceRect = CCRectMake(x, y, 25, 30);
CCArray* children = parent->getChildren();
CCObject* childObj;
bool isCollision = true;
CCARRAY_FOREACH(children, childObj) {
SpriteBase* wall = (SpriteBase*)childObj;
//自分とは判定しない
if (wall->spriteType != S_Wall) {
continue;
}
CCRect wallRect = wall->getSelfRectConverted();
if (wallRect.intersectsRect(graceRect)) {
isCollision = false;
break;
}
}
if (isCollision) {
resultPoint = gracePoint;
break;
}
}
示例12: recoveryTableCell
void CATableView::recoveryTableCell()
{
CCRect rect = this->getBounds();
rect.origin.y -= rect.size.height * 0.1f;
rect.size.height *= 1.2f;
std::map<CAIndexPath2E, CATableViewCell*>::iterator itr;
for (itr=m_pUsedTableCells.begin(); itr!=m_pUsedTableCells.end(); itr++)
{
CATableViewCell* cell = itr->second;
CC_CONTINUE_IF(cell == NULL);
CCRect cellRect = cell->getFrame();
cellRect.origin = m_pContainer->convertToWorldSpace(cellRect.origin);
cellRect.origin = this->convertToNodeSpace(cellRect.origin);
CC_CONTINUE_IF(rect.intersectsRect(cellRect));
m_pFreedTableCells[cell->getReuseIdentifier()].pushBack(cell);
cell->removeFromSuperview();
cell->resetTableViewCell();
itr->second = NULL;
CAView* line = m_pUsedLines[itr->first];
CC_CONTINUE_IF(line == NULL);
m_pFreedLines.pushBack(line);
line->removeFromSuperview();
m_pUsedLines[itr->first] = NULL;
}
}
示例13: CCRectMake
void Recipe15::update(float dt)
{
CCSprite* player = (CCSprite*) this->getChildByTag(1);
CCRect playerRect = CCRectMake(
player->getPosition().x - (player->getContentSize().width/4),
player->getPosition().y - (player->getContentSize().height/4),
player->getContentSize().width/2,
player->getContentSize().height/2);
CCSprite *food = (CCSprite*)this->getChildByTag(2);
if(food==NULL)return;
CCRect foodRect = CCRectMake(
food->getPosition().x - (food->getContentSize().width/2),
food->getPosition().y - (food->getContentSize().height/2),
food->getContentSize().width/2,
food->getContentSize().height/2);
if(playerRect.intersectsRect(foodRect) && player->isVisible())
{
this->removeChild(food,true);
player->setTexture(CCTextureCache::sharedTextureCache()->addImage("monkey02.png"));
this->scheduleOnce(schedule_selector(Recipe15::eat),0.1f);
}
}
示例14: collision
bool ObstacleDobleAir::collision(BaseVehicle &vehicle)
{
if(vehicle.getState() != kStateJump)
return false;
float y = vehicle.getPositionY() - vehicle.getPlayerY() - vehicle.getContentSize().height * 0.5f;
if(y < MAX_PLAYER_JUMP * 0.45f)
return false;
CCRect rectAir = vehicle.getAirCollision();
int i;
CCRect area;
for(i = 0; i < vCollision.size(); i++)
{
area = currentCollisionArea(vCollision[i]);
if(area.intersectsRect(rectAir))
{
return true;
}
}
return false;
}
示例15: update
void HelloWorld::update(float dt)
{
CCArray *projectilesToDelete = new CCArray;
CCObject* it = NULL;
CCObject* jt = NULL;
CCARRAY_FOREACH(_projectiles, it)
{
CCSprite *projectile = static_cast<CCSprite*>(it);
CCRect projectileRect = CCRectMake(
projectile->getPosition().x - (projectile->getContentSize().width/2),
projectile->getPosition().y -(projectile->getContentSize().height/2),
projectile->getContentSize().width,
projectile->getContentSize().height);
CCArray* targetsToDelete = new CCArray;
CCARRAY_FOREACH(_targets, jt)
{
CCSprite *target = static_cast<CCSprite*>(jt);
CCRect targetRect = CCRectMake(
target->getPosition().x - (target->getContentSize().width/2),
target->getPosition().y - (target->getContentSize().height/2),
target->getContentSize().width,
target->getContentSize().height);
if(projectileRect.intersectsRect(targetRect))
{
targetsToDelete->addObject(target);
}
}