本文整理汇总了C++中CCRect类的典型用法代码示例。如果您正苦于以下问题:C++ CCRect类的具体用法?C++ CCRect怎么用?C++ CCRect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCRect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getContentOffset
void CACollectionView::updateSectionHeaderAndFooterRects()
{
CCRect rect = this->getBounds();
rect.origin = getContentOffset();
std::vector<CCRect>::iterator itr;
for (itr = m_rSectionRects.begin(); itr != m_rSectionRects.end(); itr++)
{
CC_CONTINUE_IF(!rect.intersectsRect(*itr));
int i = itr - m_rSectionRects.begin();
CAView* header = NULL;
CAView* footer = NULL;
float headerHeight = 0;
float footerHeight = 0;
if (m_pSectionHeaderViews.find(i) != m_pSectionHeaderViews.end())
{
header = m_pSectionHeaderViews[i];
headerHeight = m_pSectionHeaderViews[i]->getFrame().size.height;
}
if (m_pSectionFooterViews.find(i) != m_pSectionFooterViews.end())
{
footer = m_pSectionFooterViews[i];
footerHeight = m_pSectionFooterViews[i]->getFrame().size.height;
}
if (header && m_bAlwaysTopSectionHeader)
{
CCPoint p1 = rect.origin;
p1.y = MAX(p1.y, itr->origin.y);
p1.y = MIN(p1.y, itr->origin.y + itr->size.height
- headerHeight - footerHeight);
header->setFrameOrigin(p1);
}
if (footer && m_bAlwaysBottomSectionFooter)
{
CCPoint p2 = CCPointZero;
p2.y = MIN(rect.origin.y + this->getBounds().size.height - footerHeight,
itr->origin.y + itr->size.height - footerHeight);
p2.y = MAX(p2.y, itr->origin.y + headerHeight);
footer->setFrameOrigin(p2);
}
}
}
示例2: itemForTouch
WXGrid* WXGridPanel::itemForTouch( cocos2d::CCTouch * touch )
{
CCPoint touchLocation = touch->getLocation();
std::vector<WXGrid*>::iterator itr = m_gridList->begin();
for (;itr!=m_gridList->end();itr++)
{
if (*itr && (*itr)->isVisible())
{
CCPoint local = (*itr)->convertToNodeSpace(touchLocation);
CCRect r = (*itr)->rect();
r.origin = CCPoint::ZERO;
if (r.containsPoint(local))
{
return (*itr);
}
}
}
return NULL;
}
示例3: CCRectUnion
CCRect CCControlUtils::CCRectUnion(const CCRect& src1, const CCRect& src2)
{
CCRect result;
float x1 = MIN(src1.getMinX(), src2.getMinX());
float y1 = MIN(src1.getMinY(), src2.getMinY());
float x2 = MAX(src1.getMaxX(), src2.getMaxX());
float y2 = MAX(src1.getMaxY(), src2.getMaxY());
result.origin=ccp(x1,x2);
result.size=CCSizeMake(x2-x1, y2-y1);
return result;
}
示例4: CCRectMake
bool Ossan::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){
const float WEIGHT_TOUCH_AREA = 0.8f;
// タッチ位置を取得
CCPoint point = pTouch->getLocation();
// スプライトの大きさ
CCSize size = this->getTexture()->getContentSize();
// スプライトの範囲
CCRect rect = CCRectMake(this->getPositionX()-size.width/2, this->getPositionY()-size.height/2, size.width * WEIGHT_TOUCH_AREA, size.height * WEIGHT_TOUCH_AREA);
// タッチ位置がスプライト内ならイベント処理するのでtrueを返す
if(rect.containsPoint(point)){
return true;
}else{
return false;
}
}
示例5: ccTouchBegan
bool DropDownListSprite:: ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
if (!m_isShowMenu)
{
CCRect rect;
rect.origin = CCPointZero;
rect.size = getContentSize();
CCPoint position = convertTouchToNodeSpace(pTouch);
if (rect.containsPoint(position))
{
m_isShowMenu = true;
addChild(m_mainMenu);
for (int i = 0, j = (int) m_selectLabels.size(); i<j; ++i)
{
if (i == m_lastSelectedIndex)
{
CCLOG("xxxx");
m_bgLayers[i]->setColor(DROPDOWNLIST_HIGHLIGHT_COLOR3);
m_showLabel->setString(m_selectLabels[i]->getString());
}
else
{
CCLOG("xxxy");
m_bgLayers[i]->setColor(DROPDOWNLIST_NORMAL_COLOR3);
}
}
return true;
}
}
return false;
}
示例6: CCARRAY_FOREACH
void HelloWorld::update(float time)
{
if (!isEnemyAdded)
{
return;
}
CCArray *projectilesToDelete = CCArray::create();
if (_projectiles->count())
{
CCObject *pObj = NULL;
CCARRAY_FOREACH(_projectiles, pObj)
{
CCSprite *projectile = (CCSprite*)pObj;
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 = CCArray::create();
CCObject *tObj = NULL;
CCARRAY_FOREACH(_targets, tObj)
{
CCSprite *target = (CCSprite*)tObj;
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);
}
else if(!targetsToDelete->containsObject(target) && player->boundingBox().intersectsRect(targetRect))
{
targetsToDelete->addObject(target);
}
}
示例7: convertTouchToNodeSpace
void ArenaCreateRoom::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;
}
CCPoint point = convertTouchToNodeSpace(pTouch);
CCRect rect;
rect.origin = m_RoomName->getPosition();
rect.size = m_RoomName->getDimensions();
rect.origin.x -= m_RoomName->getAnchorPointInPoints().x;
rect.origin.y -= m_RoomName->getAnchorPointInPoints().y;
CCRect rect1;
rect1.origin = m_RoomPassword->getPosition();
rect1.size = m_RoomPassword->getDimensions();
rect1.origin.x -= m_RoomPassword->getAnchorPointInPoints().x;
rect1.origin.y -= m_RoomPassword->getAnchorPointInPoints().y;
if (rect.containsPoint(point))
{
m_RoomName->attachWithIME();
}
else if (rect1.containsPoint(point))
{
m_RoomPassword->attachWithIME();
}
else
{
m_RoomName->detachWithIME();
m_RoomPassword->detachWithIME();
}
}
示例8: CCARRAY_FOREACH
void GameScene::updateBlocks() {
for (int i = 0; i < m_activeballs->count(); i++) {
BallSprite* ball =
dynamic_cast<BallSprite*>(m_activeballs->objectAtIndex(i));
if (!ball)
return;
CCRect ballRect = ball->boundingBox();
CCObject* jt = NULL;
CCArray* blocksToDelete = new CCArray;
CCARRAY_FOREACH(m_blocks, jt) {
CCSprite* block = dynamic_cast<CCSprite*>(jt);
// CCLOG("updateGame target.x: %f, target.y: %f, tag: %d",target->getContentSize().width, target->getContentSize().height, target->getTag());
CCRect blockRect = block->boundingBox();
//衝突判定
if (ballRect.intersectsRect(blockRect)) {
// ボールは跳ね返す
ball->bounceBall(blockRect, kTagBlock);
blocksToDelete->addObject(block);
//スコア加算
m_score += 100;
showScore();
//確率に従ってボーナスアイテムを生成する
makeItem(block);
}
}
// 当たったブロックを消す
CCARRAY_FOREACH(blocksToDelete, jt) {
CCSprite *block = dynamic_cast<CCSprite*>(jt);
m_blocks->removeObject(block);
this->removeChild(block, true);
m_blocksDestroyed++;
}
示例9: convertToNodeSpace
bool TSSprite::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
CCPoint sLocalPos = convertToNodeSpace(touch->getLocation());
CCRect sRC = CCRect(getPositionX() - getContentSize().width * getAnchorPoint().x,
getPositionY() - getContentSize().height * getAnchorPoint().y,
getContentSize().width, getContentSize().height);
sRC.origin = CCPointZero;
bool isTouched = sRC.containsPoint(sLocalPos);
if(isTouched)
{
CCLog("点中了!! x:%d y:%d", (int)sLocalPos.x, (int)sLocalPos.y);
return true;
}
else
{
CCLog("没点中了!! x:%d y:%d", (int)sLocalPos.x, (int)sLocalPos.y);
return false;
}
}
示例10: setContainerFrame
void CAScrollView::setContainerFrame(const CCPoint& point, const CCSize& size)
{
if (!size.equals(CCSizeZero))
{
CCRect rect;
rect.origin = point;
rect.size = size;
m_pContainer->setFrame(rect);
}
else
{
m_pContainer->setFrameOrigin(point);
}
CCRect rect = m_pContainer->getFrame();
m_bSlidingMinX = fabsf(rect.getMinX()) < FLT_EPSILON;
m_bSlidingMaxX = fabsf(rect.getMaxX() - this->getBounds().size.width) < FLT_EPSILON;
m_bSlidingMinY = fabsf(rect.getMinY()) < FLT_EPSILON;
m_bSlidingMaxY = fabsf(rect.getMaxY() - this->getBounds().size.height) < FLT_EPSILON;
}
示例11: shipBoundingBox
void HistoryScr::checkMeteorCollision() {
CCArray *meteorsToRemove = CCArray::create();
for (int ii = 0; ii < meteors->count(); ii++) {
CCRect meteorRect =
((CCSprite*) meteors->objectAtIndex(ii))->boundingBox();
CCRect shipRect = shipBoundingBox();
if (meteorRect.intersectsRect(shipRect) == true) {
meteorsToRemove->addObject(meteors->objectAtIndex(ii));
generateFire(
((CCSprite *) meteors->objectAtIndex(ii))->getPosition());
this->removeChild((CCSprite *) meteors->objectAtIndex(ii), true);
}
}
for (int j = 0; j < meteorsToRemove->count(); j++) {
meteors->removeObject(meteorsToRemove->objectAtIndex(j), true);
}
}
示例12: ccTouchEnded
void HelloWorld::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{
do
{
if (mUserNameTextField) {
CCPoint endPos = pTouch->getLocation();
float delta = 5.f;
if (::abs(mBeginPos.x - endPos.x) > delta
|| ::abs(mBeginPos.y - endPos.y) > delta) {
break;
}
CCRect rect;
rect = getRect(mUserNameTextField);
this->onClickTrackNode(rect.containsPoint(endPos));
}
} while (0);
}
示例13: convertToNodeSpace
bool CCSpriteButton::ccTouchBegan(CCTouch *touch, CCEvent *event)
{
m_StartTouchPoint = convertToNodeSpace(touch->getLocation());
CCRect rect;
rect.origin = CCPointZero;
rect.size = getContentSize();
m_IsEmitTouchEvent= rect.containsPoint(m_StartTouchPoint);
if(m_IsEmitTouchEvent)
{
if (m_pSelectedSprite)
{
setDisplayFrame(m_pSelectedSprite->displayFrame());
}
return true;
}
else
{
return false;
}
}
示例14: ccp
/**
* 检查是否在区域里
*/
bool UILabel::touchDown(float x,float y)
{
CCPoint pos = ccp(x,y);
pos = this->convertToNodeSpace(pos);
nowTouchPoint = ccp(x,y);
_touchIn = false;
if (text && _editable)
{
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))
{
_touchIn = true;
return true;
}
}
return false;
}
示例15: getBillboardBoundingRect
/** Transform the bounding rectangle of the 2D node on the X-Y plane into 3D. */
void CC3BillboardBoundingBoxArea::transformVolume()
{
super::transformVolume();
// Get the corners of the CCNode bounding box
CCRect br = getBillboardBoundingRect();
CCPoint bbMin = ccp(br.getMinX(), br.getMinY());
CCPoint bbMax = ccp(br.getMaxX(), br.getMaxY());
// Construct all 4 corner vertices of the local bounding box and transform each to global coordinates
m_vertices[0] = m_pNode->getGlobalTransformMatrix()->transformLocation( cc3v(bbMin.x, bbMin.y, 0.0) );
m_vertices[1] = m_pNode->getGlobalTransformMatrix()->transformLocation( cc3v(bbMin.x, bbMax.y, 0.0) );
m_vertices[2] = m_pNode->getGlobalTransformMatrix()->transformLocation( cc3v(bbMax.x, bbMin.y, 0.0) );
m_vertices[3] = m_pNode->getGlobalTransformMatrix()->transformLocation( cc3v(bbMax.x, bbMax.y, 0.0) );
/*LogTrace(@"%@ bounding volume transformed %@ MinMax(%@, %@) to (%@, %@, %@, %@)", _node,
NSStringFromCGRect(br),
NSStringFromCGPoint(bbMin), NSStringFromCGPoint(bbMax),
NSStringFromCC3Vector(_vertices[0]), NSStringFromCC3Vector(_vertices[1]),
NSStringFromCC3Vector(_vertices[2]), NSStringFromCC3Vector(_vertices[3]));*/
}