本文整理汇总了C++中cocos2d::Rect类的典型用法代码示例。如果您正苦于以下问题:C++ Rect类的具体用法?C++ Rect怎么用?C++ Rect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Rect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: placeRectToRect
cocos2d::Rect placeRectToRect(const cocos2d::Rect& placedRect, const cocos2d::Rect& placeToRect)
{
cocos2d::Rect result = placedRect;
bool bCanBePlacedInside = isRectCanBePlacesInsideRect(placedRect, placeToRect);
if (true == bCanBePlacedInside)
{
auto rectInsideResult = isRectInsideRect(placedRect, placeToRect);
if (false == rectInsideResult.bResult)
{
result.origin = placedRect.origin;
if (false == rectInsideResult.bMinX || false == rectInsideResult.bMinY)
{
Vec2 movePoint(placedRect.getMinX(), placedRect.getMinY());
movePoint = placePointToRect(movePoint, placeToRect) - movePoint;
result.origin += movePoint;
result = placeRectToRect(result, placeToRect);
}
else if (false == rectInsideResult.bMaxX || false == rectInsideResult.bMaxY)
{
Vec2 movePoint(placedRect.getMaxX(), placedRect.getMaxY());
movePoint = placePointToRect(movePoint, placeToRect) - movePoint;
result.origin += movePoint;
result = placeRectToRect(result, placeToRect);
}
}
}
return result;
}
示例2: A
cocos2d::Vec2 GameLayer::getIntersection_NPC_and_SPELayerRect(cocos2d::Rect rect ,cocos2d::Point p)
{
/*
D---------C
| |
A---------B
*/
Vec2 A(rect.getMinX(),rect.getMinY());
Vec2 B(rect.getMaxX(),rect.getMinY());
Vec2 C(rect.getMaxX(),rect.getMaxY());
Vec2 D(rect.getMinX(),rect.getMaxY());
Vec2 PlayerP = getChildByTag(kTagPlayer)->getPosition();
Vec2 npcP = p;
Vec2 point;
if ( Vec2::isSegmentIntersect(A, B, PlayerP,p)){
point = Vec2::getIntersectPoint(A,B,PlayerP,p);
}
else if (Vec2::isSegmentIntersect(B, C, PlayerP, p)){
point = Vec2::getIntersectPoint(B,C, PlayerP, p);
}
else if (Vec2::isSegmentIntersect(C, D, PlayerP, p)){
point = Vec2::getIntersectPoint(C, D, PlayerP, p);
}
else if (Vec2::isSegmentIntersect(A, D, PlayerP, p)){
point = Vec2::getIntersectPoint(A, D, PlayerP, p);
}
return point;
}
示例3: rect_adjustPointInside
cocos2d::Vec2 rect_adjustPointInside(const cocos2d::Rect& rect, const cocos2d::Vec2& pt)
{
cocos2d::Point result;
result.x = letBetween(pt.x, rect.getMinX(), rect.getMaxX());
result.y = letBetween(pt.y, rect.getMinY(), rect.getMaxY());
return result;
}
示例4: calculateCircleByRect
nav::Circle DelaunayAlgorithm::calculateCircleByRect(const cocos2d::Rect&rect)
{
CCASSERT(rect.size.width > 0 && rect.size.height > 0, "create circle must rect");
cocos2d::Point center(rect.getMidX(), rect.getMidY());
cocos2d::Point topright(rect.getMaxX(), rect.getMaxY());
float distance = center.getDistance(topright);
nav::Circle circle(center, distance);
return circle;
}
示例5: placePointToRect
cocos2d::Vec2 placePointToRect(const cocos2d::Vec2& point, const cocos2d::Rect& rect)
{
cocos2d::Vec2 result = point;
{
if (point.x < rect.getMinX())
{
result.x = rect.getMinX();
}
}
{
if (point.y < rect.getMinY())
{
result.y = rect.getMinY();
}
}
{
if (point.x > rect.getMaxX())
{
result.x = rect.getMaxX();
}
}
{
if (point.y > rect.getMaxY())
{
result.y = rect.getMaxY();
}
}
return result;
}
示例6: checkChildType
bool TeachLayer::checkChildType(cocos2d::Node *pNode, cocos2d::Rect stencilRect)
{
if (!pNode) return false;
if (0 >= pNode->getChildrenCount()) return false;
for (auto child : pNode->getChildren())
{
if (dynamic_cast<SpriteButton*>(child))
{
auto spriteButton = dynamic_cast<SpriteButton*>(child);
Rect btnRect = getNodeRect(spriteButton);
if (stencilRect.intersectsRect(btnRect))
{
removeFromParent();
// spriteButton->execCallBackEvent();
return true;
}
}
}
for (auto child : pNode->getChildren())
{
if (checkChildType(child, stencilRect))
return true;
}
return false;
}
示例7: createCheckerWithRect
APTouchChecker APTouchManager::createCheckerWithRect(const cocos2d::Rect& rect) {
return [rect](cocos2d::Touch* touch)->bool{
return rect.containsPoint(touch->getLocation());
};
}
示例8: isRectInsideRect
tRectInRectResult isRectInsideRect(const cocos2d::Rect & lhs, const cocos2d::Rect & rhs)
{
bool bMinX = lhs.getMinX() >= rhs.getMinX();
bool bMinY = lhs.getMinY() >= rhs.getMinY();
bool bMaxX = lhs.getMaxX() <= rhs.getMaxX();
bool bMaxY = lhs.getMaxY() <= rhs.getMaxY();
return tRectInRectResult(bMinX, bMinY, bMaxX, bMaxY);
}
示例9:
void Pipe2::MakePipeBody(cocos2d::Layer *layer, b2World *world, cocos2d::Rect rect){
auto Pipe = Sprite::create("pipe.png", rect);
Pipe->setPosition(rect.getMidX(),rect.getMidY());
layer->addChild(Pipe);
//Pipe->setScale(0.5);
b2BodyDef PipeBodyDef;
PipeBodyDef.type = b2_kinematicBody; //gravitity is not for pipes
PipeBodyDef.position.Set(rect.getMidX()/SCALE_RATIO, rect.getMidY()/SCALE_RATIO);
PipeBodyDef.userData = Pipe;
auto PipeBody = world->CreateBody(&PipeBodyDef);
float a = Pipe->getContentSize().width;//*0.7;
float b = Pipe->getContentSize().height;//*0.9;
float sizeX = a/(2*SCALE_RATIO);
float sizeY = b/(2*SCALE_RATIO);
b2PolygonShape polygon;
polygon.SetAsBox(sizeX, sizeY); //a 4x2 rectangle !!может округлять в большую сторону; ORIGINY слишком большой OrigiinX маленький(
//polygon.SetAsBox(1, sizeY);
b2FixtureDef PipeShapeDef;
PipeShapeDef.shape = &polygon;
PipeShapeDef.density = 0;
PipeShapeDef.friction = 0;
PipeShapeDef.restitution = 0;
PipeBody->CreateFixture(&PipeShapeDef);
PipeBody->SetLinearVelocity( b2Vec2(-3,0));
}
示例10: setTextureRect
void Scale9Sprite::setTexture(cocos2d::Texture2D *texture, const cocos2d::Rect &rect) {
_contentSizeDirty = true;
DynamicBatchNode::setTexture(texture);
if (rect.equals(cocos2d::Rect::ZERO)) {
setTextureRect(cocos2d::Rect(0, 0, texture->getContentSize().width, texture->getContentSize().height));
} else {
setTextureRect(rect);
}
}
示例11: getPosition
void BlueParticles::SetArea(cocos2d::Rect rect, bool draw)
{
m_area = rect;
m_area.origin += getPosition();
if (draw)
{
cocos2d::DrawNode* draw = cocos2d::DrawNode::create();
draw->drawRect(cocos2d::Vec2::ZERO, cocos2d::Vec2(m_area.size.width, m_area.size.height), cocos2d::Color4F(1.0f, 0.0f, 0.0f, 0.5f));
addChild(draw);
}
cocos2d::Rect textRect = cocos2d::Rect(rect.getMidX(), rect.getMidY(), rect.getMaxX() - rect.getMinX(), rect.getMaxY() - rect.getMinY());
this->setTextureRect(rect);
cocos2d::Texture2D::TexParams params = cocos2d::Texture2D::TexParams();
params.magFilter = GL_LINEAR;
params.minFilter = GL_LINEAR;
params.wrapS = GL_REPEAT;
params.wrapT = GL_REPEAT;
getTexture()->setTexParameters(params);
}
示例12: getShowCells
void TableView::getShowCells(const cocos2d::Rect& area, std::vector<uint16_t>* dst)
{
Rect _cellRect;
for (int i = 0; i < m_totalCnt; ++i)
{
getCellRect(i, &_cellRect);
if (!area.intersectsRect(_cellRect))
continue;
dst->push_back(i);
}
}
示例13: getTexture
void DynamicSprite::setTextureRect(const cocos2d::Rect &rect) {
auto tex = getTexture();
if (rect.equals(cocos2d::Rect::ZERO) && tex) {
_textureRect = cocos2d::Rect(0, 0, tex->getPixelsHigh(), tex->getPixelsWide());
_contentSizeDirty = true;
} else {
if (!_textureRect.equals(rect)) {
_textureRect = rect;
_contentSizeDirty = true;
}
}
if (_autofit == Autofit::None) {
setContentSize(cocos2d::Size(_textureRect.size.width / _density, _textureRect.size.height / _density));
}
}
示例14: getTexture
bool Scale9Sprite::init(cocos2d::Texture2D *tex, cocos2d::Rect rect, cocos2d::Rect capInsets) {
if (!DynamicBatchNode::init(tex)) {
return false;
}
if (rect.equals(cocos2d::Rect::ZERO)) {
rect.size = getTexture()->getContentSize();
}
_textureRect = rect;
_capInsets = capInsets;
_contentSize = _textureRect.size;
setCascadeColorEnabled(true);
setCascadeOpacityEnabled(true);
return true;
}
示例15: GetTileInfoByGid
bool TMXFile::GetTileInfoByGid(uint32_t iGid, const char*& outTexPath, cocos2d::Rect& outRect, const TMXCustomPropertyList*& outPropertyList)const
{
for (auto& p : m_vecTileSet)
{
if (p->GetFirstGid() <= iGid && p->GetFirstGid() + p->GetTileMaxCount() > iGid)
{
uint32_t iIndex = iGid - p->GetFirstGid();
outTexPath = p->GetTexturePath().c_str();
outPropertyList = p->GetTileCustomPropertyList(iIndex);
uint32_t x = iIndex % p->GetWidthCount();
uint32_t y = iIndex / p->GetWidthCount();
outRect.setRect(x * p->GetTileWidth(), y * p->GetTileHeight(), p->GetTileWidth(), p->GetTileHeight());
return true;
}
}
return false;
}