コード例 #1
0
ファイル: PipeBox.cpp プロジェクト: valkoz/FlappyClone
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));



}
コード例 #2
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;
}
コード例 #3
0
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);
}
コード例 #4
0
ファイル: Geometry.cpp プロジェクト: adroitly/boom
 cocos2d::Point rect_getMiddle(const cocos2d::Rect& rect)
 {
     return cocos2d::Point(rect.getMidX(), rect.getMidY());
 }
コード例 #5
0
ファイル: SPDrawPath.cpp プロジェクト: SBKarr/stappler
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);
}
コード例 #6
0
ファイル: SPDrawPath.cpp プロジェクト: SBKarr/stappler
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();
}