本文整理汇总了C++中CCRect::getMidX方法的典型用法代码示例。如果您正苦于以下问题:C++ CCRect::getMidX方法的具体用法?C++ CCRect::getMidX怎么用?C++ CCRect::getMidX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCRect
的用法示例。
在下文中一共展示了CCRect::getMidX方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initTerritory
/*!
* Determines initial territory size for this player based on the size of the screen and the location of the initial touch.
* Sets player identifier based on initial territory.
*
* @param screenBox Size of the screen.
*/
void Player::initTerritory(CCRect screenBox) {
this->territory = CCRectMake(screenBox.origin.x, screenBox.origin.y, screenBox.size.width, screenBox.size.height);
territory.size.width /= 2;
if (startingPoint.x < screenBox.getMidX()) {
territory.origin.x = screenBox.origin.x / 2;
if (GameManager::sharedManager()->tabletDevice()) {
if (startingPoint.y > screenBox.getMidY()) {
this->_identifier = GameManager::kPlayer1;
} else {
this->_identifier = GameManager::kPlayer3;
}
} else {
this->_identifier = GameManager::kPlayer1;
}
} else {
territory.origin.x = screenBox.origin.x / 2 + screenBox.size.width / 2;
if (GameManager::sharedManager()->tabletDevice()) {
if (startingPoint.y > screenBox.getMidY()) {
this->_identifier = GameManager::kPlayer2;
} else {
this->_identifier = GameManager::kPlayer4;
}
} else {
this->_identifier = GameManager::kPlayer2;
}
}
}
示例2: 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;
}
示例3: onMovingToTarget
bool AllyUnit::onMovingToTarget( float dt )
{
// let enemy stop running
// note: the pos is not the center point of collision rect!
// 1. get distance color(collision) rect of ally
//CCRect targetCollisionRect = enemy->getCollisionRect();
if (!mPreTargetCollisionRect.equals(mTargetCollisionRect) )
{
CCRect CollisionRect = this->getCollisionRect();
CCPoint destColorRectLeftTop;
if(mTargetCollisionRect.getMidX() > CollisionRect.getMidX())
{
// move to left of the target
destColorRectLeftTop.x = mTargetCollisionRect.getMinX() - mDefualtColorRect.size.width;
}
else
{
// move to right of the target
destColorRectLeftTop.x = mTargetCollisionRect.getMaxX();
}
destColorRectLeftTop.y = mTargetCollisionRect.getMinY() + mDefualtColorRect.size.height;
CCPoint destSpriteRectLeftTop = CCPoint(
destColorRectLeftTop.x - mDefualtColorRect.origin.x,
destColorRectLeftTop.y + mDefualtColorRect.origin.y
);
CCSize size = this->getContentSize();
mDestinationPos = CCPoint(
destSpriteRectLeftTop.x + size.width / 2,
destSpriteRectLeftTop.y - size.height / 2 + rangedRand(0, 5)
);
}
return onMoving(dt, mDestinationPos);
}
示例4: isCollisionTop
bool GameLayer::isCollisionTop(CCRect roleBox, CCRect collisionBox) {
CCPoint targetPoint = ccp(roleBox.getMidX(), roleBox.getMaxY());
return collisionBox.containsPoint(targetPoint);
}