Ejemplo n.º 1
0
         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;
         }
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
         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;
         }
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
APTouchChecker APTouchManager::createCheckerWithRect(const cocos2d::Rect& rect) {

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

	};
}
Ejemplo n.º 8
0
         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);
         }
Ejemplo n.º 9
0
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));



}
Ejemplo n.º 10
0
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);
	}
}
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);
}
Ejemplo n.º 12
0
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);
	}
}
Ejemplo n.º 13
0
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));
	}
}
Ejemplo n.º 14
0
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;
}
Ejemplo n.º 15
0
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;
}
Ejemplo n.º 16
0
 cocos2d::Point rect_getMiddle(const cocos2d::Rect& rect)
 {
     return cocos2d::Point(rect.getMidX(), rect.getMidY());
 }
Ejemplo n.º 17
0
bool RunnerSprite::isCollisionWithRight(cocos2d::Rect box){
    auto manBox = mRunner->boundingBox();
    Vec2 manPoint = Vec2(manBox.getMaxX(),manBox.getMidY());
    return box.containsPoint(manPoint);
}
Ejemplo n.º 18
0
void Path::addOval(const cocos2d::Rect& oval) {
	moveTo(oval.getMaxX(), oval.getMidY());
	arcTo(oval.getMidX(), oval.getMidY(), oval.size.width/2, oval.size.height/2, 0.0f, 360.0_to_rad, 0.0f);
	closePath();
}
Ejemplo n.º 19
0
void Path::addArc(const cocos2d::Rect& oval, float startAngle, float sweepAngle) {
	arcTo(oval.getMidX(), oval.getMidY(), oval.size.width/2, oval.size.height/2, startAngle, sweepAngle, 0.0f);
}