当前位置: 首页>>代码示例>>C++>>正文


C++ cocos2d::Rect类代码示例

本文整理汇总了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;
         }
开发者ID:svlad-90,项目名称:theWorld,代码行数:32,代码来源:Helper.cpp

示例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;
}
开发者ID:zuokaihuang,项目名称:MyFlow,代码行数:32,代码来源:GameLayer.cpp

示例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;
 }
开发者ID:adroitly,项目名称:boom,代码行数:7,代码来源:Geometry.cpp

示例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;
}
开发者ID:spzktshow,项目名称:BigDipper,代码行数:9,代码来源:NVDelaunayAlgorithm.cpp

示例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;
         }
开发者ID:svlad-90,项目名称:theWorld,代码行数:34,代码来源:Helper.cpp

示例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;
}
开发者ID:LeeWei92,项目名称:CocosGui,代码行数:27,代码来源:TeachLayer.cpp

示例7: createCheckerWithRect

APTouchChecker APTouchManager::createCheckerWithRect(const cocos2d::Rect& rect) {

	return [rect](cocos2d::Touch* touch)->bool{
		return rect.containsPoint(touch->getLocation());

	};
}
开发者ID:EzKorry,项目名称:testunit36,代码行数:7,代码来源:apTouchManager.cpp

示例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);
         }
开发者ID:svlad-90,项目名称:theWorld,代码行数:9,代码来源:Helper.cpp

示例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));



}
开发者ID:valkoz,项目名称:FlappyClone,代码行数:46,代码来源:PipeBox.cpp

示例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);
	}
}
开发者ID:SBKarr,项目名称:stappler,代码行数:9,代码来源:SPScale9Sprite.cpp

示例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);
}
开发者ID:tofurama3000,项目名称:The-Obscurity-Project,代码行数:19,代码来源:BlueParticles.cpp

示例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);
	}
}
开发者ID:wjezxujian,项目名称:Android_VS,代码行数:11,代码来源:TableView.cpp

示例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));
	}
}
开发者ID:SBKarr,项目名称:stappler,代码行数:15,代码来源:SPDynamicSprite.cpp

示例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;
}
开发者ID:SBKarr,项目名称:stappler,代码行数:17,代码来源:SPScale9Sprite.cpp

示例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;
}
开发者ID:9chu,项目名称:cocos2dx-sokoban,代码行数:19,代码来源:TMXFile.cpp


注:本文中的cocos2d::Rect类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。