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


C++ PhysicsBody::setDynamic方法代码示例

本文整理汇总了C++中PhysicsBody::setDynamic方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsBody::setDynamic方法的具体用法?C++ PhysicsBody::setDynamic怎么用?C++ PhysicsBody::setDynamic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhysicsBody的用法示例。


在下文中一共展示了PhysicsBody::setDynamic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: createPhysicsBody

void Level::createPhysicsBody()
{
	for (auto& object : _collisionObjectGroup->getObjects())
	{
		float objectX = object.asValueMap().at("x").asFloat(),
			objectY = object.asValueMap().at("y").asFloat();
		Size s = Size(object.asValueMap().at("width").asFloat(), 
					  object.asValueMap().at("height").asFloat());

		if (object.asValueMap().find("polylinePoints") == object.asValueMap().end())
		{
			PhysicsShapeBox *box = PhysicsShapeBox::create(s, PhysicsMaterial(0.0f, 0.0f, 1.0f),
				Vec2(objectX + s.width / 2, objectY + s.height / 2));
			box->setTag(0);

			PhysicsBody *body = PhysicsBody::create();
			body->setDynamic(false);
			body->setContactTestBitmask(0xFFFFFFFF);
			body->addShape(box);

			Node* node = Node::create();
			node->setPhysicsBody(body);
			//addChild(node);
			_physicsNodes.pushBack(node);
		}
		else
		{
			Vec2 t[2];
			int i = 0;
			for (auto& point : object.asValueMap().at("polylinePoints").asValueVector())
			{
				// convert the points' local coordinates to the world coordinates
				// by doing a translation using the object's position vector

				// We invert the local y because it's based on the top-left space in Tiled
				t[i].x = point.asValueMap().at("x").asInt() + objectX;
				t[i].y = -point.asValueMap().at("y").asInt() + objectY;
				i++;
			}
			PhysicsShapeEdgeSegment *line = PhysicsShapeEdgeSegment::create(t[0], t[1], 
				PhysicsMaterial(0.0f, 0.0f, 1.0f));
			line->setTag(0);

			PhysicsBody *body = PhysicsBody::create();
			body->setDynamic(false);
			body->setContactTestBitmask(0xFFFFFFFF);
			body->addShape(line);

			Node* node = Node::create();
			node->setPhysicsBody(body);
			//addChild(node);
			_physicsNodes.pushBack(node);
		}
	}
}
开发者ID:MysticVector,项目名称:Sonarin,代码行数:55,代码来源:Level.cpp

示例2: configPipeRandom

void PipeSprite::configPipeRandom()
{

    Size visiableSize = Director::getInstance()->getVisibleSize();
    Vec2 visiableOrigin = Director::getInstance()->getVisibleOrigin();
    
    /**********************config upper pipe********************************/
    mUpperPipe->setPosition(Vec2(0, mPipeAccessHeight + 60));
    upperPipeExpand->setPosition(mUpperPipe->getPosition().x, mUpperPipe->getContentSize().height);
    upperPipeExpand->setScaleY((visiableSize.height - mUpperPipe->getPosition().y - mUpperPipe->getContentSize().height) / upperPipeExpand->getContentSize().height);
    /**********************config upper pipe********************************/
    
    /**********************config bottom pipe********************************/
    mBottomPipe->setPosition(Vec2(0, mPipeAccessHeight - 60));
    bottomPipeExpand->setPosition(0, -mBottomPipe->getPosition().y + mLandHeight);
    bottomPipeExpand->setScaleY((mBottomPipe->getPosition().y - mLandHeight) / bottomPipeExpand->getContentSize().height);
    /**********************config bottom pipe********************************/
    
    /****************add upper physics body*******************/
    if (mUpperPipe->getPhysicsBody() != nullptr)
    {
        mUpperPipe->removeComponent(mUpperPipe->getPhysicsBody());
    }
    PhysicsBody * newUpperPipeBody = PhysicsBody::createBox(Size(mUpperPipe->getContentSize().width,
                                                              visiableSize.height - mUpperPipe->getPosition().y),
                                                            PhysicsMaterial(1.0, 1.0, 0));
    newUpperPipeBody->setPositionOffset(Vec2(0, (visiableSize.height - mUpperPipe->getPosition().y - mUpperPipe->getContentSize().height) / 2));
    newUpperPipeBody->setGravityEnable(false);
    newUpperPipeBody->setDynamic(false);
    newUpperPipeBody->setContactTestBitmask(1);
    newUpperPipeBody->setCollisionBitmask(2);
    mUpperPipe->setPhysicsBody(newUpperPipeBody);
    /****************add upper physics body*******************/
    
    /****************add bottom physics body*******************/
    if (mBottomPipe->getPhysicsBody() != nullptr)
    {
        mBottomPipe->removeComponent(mBottomPipe->getPhysicsBody());
    }
    PhysicsBody * newBottomPipeBody = PhysicsBody::createBox(Size(mBottomPipe->getContentSize().width,
                                                                  mBottomPipe->getPosition().y - mLandHeight + mBottomPipe->getContentSize().height),
                                                             PhysicsMaterial(1.0, 1.0, 0));
    newBottomPipeBody->setPositionOffset(Vec2(0, -(mBottomPipe->getPosition().y - mLandHeight) / 2));
    newBottomPipeBody->setGravityEnable(false);
    newBottomPipeBody->setDynamic(false);
    newBottomPipeBody->setContactTestBitmask(1);
    newBottomPipeBody->setCollisionBitmask(2);
    mBottomPipe->setPhysicsBody(newBottomPipeBody);
    /****************add bottom physics body*******************/
}
开发者ID:lhCheung1991,项目名称:flappybird_cocos2dx_2,代码行数:50,代码来源:PipeSprite.cpp

示例3: init

bool Car::init(string fileName)
{
	if (!Node::init())
		return false;

	//-------------  Khởi tạo sprite chính -------------
	_sprite = Sprite::create(fileName);
	_sprite->setPosition(0, 0);
	_sprite->setAnchorPoint(Vec2(0.25, 0.25));
	this->addChild(_sprite);

	
	//-------------   Physic Body  --------------
	body = PhysicsBody::createBox(Size(_sprite->getContentSize().width / 2, _sprite->getContentSize().height / 2), PhysicsMaterial(100.0f, 0.0f, 100.0f), Vec2::ZERO);
	body->setDynamic(false);
	body->setTag(Tags::OBSTRUCTION);
	body->setCollisionBitmask(1);
	body->setContactTestBitmask(1);
	this->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	this->setPhysicsBody(body);


	//Mai xe
	auto nodeCar = Node::create();
	nodeCar->setPosition(_sprite->getContentSize().width * 2.1 / 4, _sprite->getContentSize().height * 2.3 / 3);
	nodeCar->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	_sprite->addChild(nodeCar);
	PhysicsBody * bodyNodeCar = PhysicsBody::createBox(Size(_sprite->getContentSize().width * 2.5 / 5, _sprite->getContentSize().height / 3), PhysicsMaterial(100.0f, 0.0f, 100.0f), Vec2::ZERO);
	bodyNodeCar->setTag(Tags::MAIXE);
	bodyNodeCar->setDynamic(false);
	bodyNodeCar->setContactTestBitmask(1);
	bodyNodeCar->setCollisionBitmask(1);
	nodeCar->setPhysicsBody(bodyNodeCar);

	//Score
	auto nodeScore = Node::create();
	nodeScore->setPosition(_sprite->getContentSize().width * 2.1 / 4, _sprite->getContentSize().height);
	nodeScore->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	_sprite->addChild(nodeScore);
	PhysicsBody * bodyNodeScore = PhysicsBody::createBox(Size(_sprite->getContentSize().width * 2.5 / 5, Config::screenSize.height), PhysicsMaterial(100.0f, 0.0f, 100.0f), Vec2::ZERO);
	bodyNodeScore->setTag(Tags::NODE_SCORE);
	bodyNodeScore->setDynamic(false);
	bodyNodeScore->setCategoryBitmask(0x01);
	bodyNodeScore->setContactTestBitmask(1);
	bodyNodeScore->setCollisionBitmask(0x02);
	nodeScore->setPhysicsBody(bodyNodeScore);

	return true;
}
开发者ID:HoangDang0306,项目名称:Skater,代码行数:49,代码来源:Car.cpp

示例4: init

bool HeroSprite::init() {
	bool bRet = false;

	do {
		CC_BREAK_IF(!Sprite::initWithSpriteFrameName("heroStand_0001.png"));

		Size heroSize = this->getContentSize();
		PhysicsBody *body = PhysicsBody::createBox(heroSize-Size(0,16), PhysicsMaterial(0, 0, 0));
		body->setLinearDamping(0.0f);
		body->setDynamic(true);
		body->setGravityEnable(true);
		body->setTag(TAG_HERO_PHYS_BODY);
		body->setCategoryBitmask(1<<2);
		body->setContactTestBitmask(1<<0 | 1<<1);
		body->setMass(50);
		body->setRotationEnable(false);

		this->setPhysicsBody(body);

		mState = STATE_IDLE;
        mRunAnimate = NULL;
        mSmokeRunAnimate = NULL;

		bRet = true;
	} while(0);

	return bRet;
}
开发者ID:liangxiaoju,项目名称:codes,代码行数:28,代码来源:HeroSprite.cpp

示例5: initPhyscsObject

void ShowLayer::initPhyscsObject(Rect* m)
{
	for (int i = 0; i < 26; i++)
	{
		Sprite* sp = Sprite::create();
		auto maskLayer = LayerColor::create(Color4B(0, 0, 255, 200));
		maskLayer->setContentSize(m[i].size);
		maskLayer->setAnchorPoint(Vec2(0, 0));
		sp->addChild(maskLayer, 15);

		PhysicsBody* playerBody = PhysicsBody::createBox(m[i].size, PHYSICSBODY_MATERIAL_DEFAULT);

		playerBody->setDynamic(false);

		//设置质量
		playerBody->getShape(0)->setMass(100);

		//设置物体是否受重力系数影响
		playerBody->setGravityEnable(false);

		playerBody->setCategoryBitmask(3);
		playerBody->setContactTestBitmask(3);
		playerBody->setCollisionBitmask(3);

		sp->setContentSize(m[i].size);
		sp->setPosition(Vec2(m[i].getMidX(), m[i].getMidY()));
		sp->setAnchorPoint(Vec2(0.0, 0.0));
		sp->setPhysicsBody(playerBody);

		this->addChild(sp);
	}
}
开发者ID:zsn6493,项目名称:EATFUZI,代码行数:32,代码来源:ShowLayer.cpp

示例6: addPhysics

void Person::addPhysics()
{
	auto size = (this->getBoundingBox()).size;
	log("%lf %lf", size.width, size.height);
	auto material = PhysicsMaterial(100.0f, 0.01f, 1.0f);
	if(_type == TYPE::HERO) size.width /= 2;
	PhysicsBody *body = PhysicsBody::createBox(Size(size.width,size.height),material);
//	body->addShape(PhysicsShapeBox::create(Size(size.width,size.height),material));
	body->setCategoryBitmask(_type);
	if(_type == TYPE::MONSTER) 
	{
		body->setCollisionBitmask(TYPE::MONSTER  | TYPE::BRICK | TYPE::GROUND | 
			TYPE::TANGH | TYPE::BULLET | TYPE::BOSS | TYPE::PLANK);
		body->setContactTestBitmask(TYPE::MONSTER | TYPE::HERO | TYPE::BRICK | 
			TYPE::TANGH | TYPE::BULLET | TYPE::BOSS);
	}
	else if(_type == TYPE::HERO)
	{
		body->setCollisionBitmask( TYPE::HERO | TYPE::GROUND | TYPE::TANGH | TYPE::PLANK);
		body->setContactTestBitmask(TYPE::MONSTER | TYPE::HERO | TYPE::GROUND | 
			TYPE::TANGH | TYPE::BULLET | TYPE::TRAP | TYPE::BOSS |
			TYPE::BULLETENEMY | TYPE::PLANK | TYPE::BUFF);
	}
	else if(_type == TYPE::BOSS)
	{
		body->setCollisionBitmask( TYPE::HERO | TYPE::GROUND | TYPE::BOSS | PLANK);
		body->setContactTestBitmask( TYPE::HERO | TYPE::GROUND | TYPE::BOSS);
	}
	body->setDynamic(true);
	body->setLinearDamping(0.0f);
	body->setRotationEnable(false);
	body->setGravityEnable(true);
	this->setPhysicsBody(body);
}
开发者ID:joyfish,项目名称:gameClient,代码行数:34,代码来源:Person.cpp

示例7: initBody

void SpeedUpProtect::initBody()
{
	auto s = getContentSize();
	Vec2 vec[7] = 
	{
		Vec2(0,0),
		Vec2(s.width * 0.1, s.height * 0.4),
		Vec2(s.width * 0.26, s.height * 0.72),
		Vec2(s.width * 0.5, s.height),
		Vec2(s.width * 0.74, s.height * 0.72),
		Vec2(s.width * 0.9, s.height * 0.4),
		Vec2(s.width,0),
	};

	PhysicsBody* body = PhysicsBody::createPolygon(vec, 7, PHYSICSBODY_MATERIAL_DEFAULT, Vec2(-s.width*0.5,-s.height*0.5));
	body->setGravityEnable(false);
	body->setRotationEnable(false);
	body->setDynamic(false);
	body->setMass(10000000);
	body->setCategoryBitmask(SELF_SCOPE_CATEGORYBITMASK);
	body->setCollisionBitmask(SELF_SCOPE_COLLISIONBITMASK);
	body->setContactTestBitmask(SELF_SCOPE_CONTACTTESTBITMASK);
	setPhysicsBody(body);
	setInvincible(true);
	m_ContactPro.hurts = -Ene_Plane_Hp_max - 10;
}
开发者ID:Chonger8888,项目名称:project,代码行数:26,代码来源:SpecialBody.cpp

示例8: init

bool guaiwu_js::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    auto root_layer = CSLoader::createNode("LayerUI/Other/guaiwu.csb");
    addChild(root_layer);
    auto rooaby = root_layer->getChildByName<Node*>("FileNode_1")->getChildByName<Sprite*>("anim_guaiwu_zo0001_2");
    PhysicsBody* phybody = PhysicsBody::createBox(Size(rooaby->getContentSize().width-8, rooaby->getContentSize().height-20));
    phybody->setTag(400001);
    phybody->setMass(3000);
    phybody->setRotationEnable(false);
    phybody->setCategoryBitmask(0x01);
    phybody->setCollisionBitmask(0x02);
    phybody->setContactTestBitmask(0x01);
    phybody->setDynamic(true);
    rooaby->setPhysicsBody(phybody);
    guaiwu = CSLoader::createTimeline("Node/animation/guaiwujs.csb");
    guaiwu->gotoFrameAndPlay(0,35, true);
    root_layer->runAction(guaiwu);
    scheduleUpdate();
    //添加碰撞事件
    auto collisionlistener = EventListenerPhysicsContact::create();
    collisionlistener->onContactBegin =CC_CALLBACK_1(guaiwu_js::onCollisionBegin, this);
    collisionlistener->onContactSeparate = CC_CALLBACK_1(guaiwu_js::onContactSeparate,this);
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(collisionlistener, this);
    return true;
}
开发者ID:jian22446688,项目名称:DesertTour,代码行数:31,代码来源:guaiwu_js.cpp

示例9: init

bool LandSprite::init()
{
    if (!Sprite::init())
    {
        return false;
    }
    
    Size visiableSize = Director::getInstance()->getVisibleSize();
    Vec2 visiableOrigin = Director::getInstance()->getVisibleOrigin();
    
    Sprite * landSprite1 = Sprite::create("assets/land.png");
    landSprite1->setAnchorPoint(Vec2(0, 0));
    landSprite1->setPosition(Vec2(visiableOrigin.x, visiableOrigin.y));
    landSprite1->setScaleX(visiableSize.width / landSprite1->getContentSize().width / 2);
    
    Sprite * landSprite2 = Sprite::create("assets/land.png");
    landSprite2->setAnchorPoint(Vec2(0, 0));
    landSprite2->setPosition(Vec2(visiableOrigin.x + visiableSize.width / 2, visiableOrigin.y));
    landSprite2->setScaleX(visiableSize.width / landSprite2->getContentSize().width / 2);
    
    Sprite * landSprite3 = Sprite::create("assets/land.png");
    landSprite3->setAnchorPoint(Vec2(0, 0));
    landSprite3->setPosition(Vec2(visiableOrigin.x + visiableSize.width, visiableOrigin.y));
    landSprite3->setScaleX(visiableSize.width / landSprite3->getContentSize().width / 2);
    
    Sprite * landSprite4 = Sprite::create("assets/land.png");
    landSprite4->setAnchorPoint(Vec2(0, 0));
    landSprite4->setPosition(Vec2(visiableOrigin.x + visiableSize.width * 1.5, visiableOrigin.y));
    landSprite4->setScaleX(visiableSize.width / landSprite4->getContentSize().width / 2);
    
    Node * landAnimNode = Node::create();    // node hold the land animation
    landAnimNode->addChild(landSprite1);
    landAnimNode->addChild(landSprite2);
    landAnimNode->addChild(landSprite3);
    landAnimNode->addChild(landSprite4);
    
    MoveBy * landForward = MoveBy::create(5, Vec2(-visiableSize.width, 0));
    MoveBy * landBackward = MoveBy::create(0.001, Vec2(visiableSize.width, 0));
    Sequence * moveSeq = Sequence::create(landForward, 0.001, landBackward,NULL);
    landSprite1->runAction(RepeatForever::create(moveSeq));
    landSprite2->runAction(RepeatForever::create(moveSeq->clone()));
    landSprite3->runAction(RepeatForever::create(moveSeq->clone()));
    landSprite4->runAction(RepeatForever::create(moveSeq->clone()));
    
    this->addChild(landAnimNode);
    this->setAnchorPoint(Vec2(0, 0));
    this->setContentSize(Size(visiableSize.width, landSprite1->getContentSize().height));
    
    PhysicsBody * landPhysicsBody = PhysicsBody::createBox(Size(visiableSize.width, landSprite1->getContentSize().height), PhysicsMaterial(1, 1, 0));
    landPhysicsBody->setGravityEnable(false);
    landPhysicsBody->setDynamic(false);
    landPhysicsBody->setContactTestBitmask(1);
    landPhysicsBody->setCollisionBitmask(2);
    this->setPhysicsBody(landPhysicsBody);
    
    
    return true;
}
开发者ID:lhCheung1991,项目名称:flappybird_cocos2dx_2,代码行数:58,代码来源:LandSprite.cpp

示例10: setCollider

void HelloWorld::setCollider (int tag){
    Sprite* floor = (Sprite *)ScreenUtil::getChildbyTagRecursively(this, tag);
    auto size = Size(floor ->getContentSize().width * floor->getScaleX()
                     , floor ->getContentSize().height * floor->getScaleY());
    PhysicsBody* floorPb = PhysicsBody::createBox(size);
    
    floorPb->setDynamic(false);
    floor->setPhysicsBody(floorPb);
}
开发者ID:kamasujp,项目名称:freak-flick,代码行数:9,代码来源:HelloWorldScene.cpp

示例11: setPhysical

void BoySprite::setPhysical() {
	// add the physical body
	PhysicsBody *body = PhysicsBody::create();
	body->addShape(NORMAL_SHAPE);
	body->setDynamic(true);
	body->setLinearDamping(0.0f);
	body->setRotationEnable(false);
	this->setPhysicsBody(body);
}
开发者ID:OiteBoys,项目名称:StreetBoy,代码行数:9,代码来源:BoySprite.cpp

示例12: initPhysics

void Ball::initPhysics(){
	PhysicsBody *spriteBody = PhysicsBody::createCircle(this->getSprite()->getBoundingBox().size.width , PHYSICSBODY_MATERIAL_DEFAULT);
	spriteBody->setDynamic(true);
	spriteBody->getShape(0)->setRestitution(1.0f);
	spriteBody->getShape(0)->setFriction(0.0f);
	spriteBody->getShape(0)->setDensity(1.0f);
	spriteBody->getShape(0)->setMass(100);
	spriteBody->setGravityEnable(false);
	spriteBody->setVelocity(this->velocity);
	this->getSprite()->setPhysicsBody(spriteBody);
}
开发者ID:TheWindShan,项目名称:cocos2dx-project,代码行数:11,代码来源:Ball.cpp

示例13: initPhysics

void Hero::initPhysics() {
    PhysicsBody* pbody = nullptr;
    pbody = PhysicsBody::createBox(getSize());
    pbody->setDynamic(true);
    pbody->setRotationEnable(false);
    pbody->setMoment(0);
    pbody->setMass(0.8);
    pbody->setContactTestBitmask(1);
    pbody->setGravityEnable(false);
    getSprite()->setPhysicsBody(pbody);
    
    mEnableGravity = true;
    mEnableForceField = true;
}
开发者ID:zxy2845986,项目名称:jumpproj,代码行数:14,代码来源:Blocks.cpp

示例14: createEdgeSegment

PhysicsBody* PhysicsBody::createEdgeSegment(const Vec2& a, const Vec2& b, const PhysicsMaterial& material, float border/* = 1*/)
{
    PhysicsBody* body = new (std::nothrow) PhysicsBody();
    if (body && body->init())
    {
        body->addShape(PhysicsShapeEdgeSegment::create(a, b, material, border));
        body->setDynamic(false);
        body->autorelease();
        return body;
    }
    
    CC_SAFE_DELETE(body);
    return nullptr;
}
开发者ID:bonlai,项目名称:3kaigame,代码行数:14,代码来源:CCPhysicsBody.cpp

示例15: createEdgeBox

PhysicsBody* PhysicsBody::createEdgeBox(const Size& size, const PhysicsMaterial& material, float border/* = 1*/, const Vec2& offset)
{
    PhysicsBody* body = new (std::nothrow) PhysicsBody();
    if (body && body->init())
    {
        body->addShape(PhysicsShapeEdgeBox::create(size, material, border, offset));
        body->setDynamic(false);
        body->autorelease();
        return body;
    }
    
    CC_SAFE_DELETE(body);

    return nullptr;
}
开发者ID:bonlai,项目名称:3kaigame,代码行数:15,代码来源:CCPhysicsBody.cpp


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