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


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

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


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

示例1: 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

示例2: if

PhysicsBody *PEShapeCache::getPhysicsBodyByName(const std::string name)
{
	BodyDef *bd = bodyDefs.at(name);
	CCASSERT(bd != nullptr, "Body not found");
	PhysicsBody *body = PhysicsBody::create(bd->mass, bd->momentum);
	body->setPositionOffset(bd->anchorPoint);
	for (auto fd : bd->fixtures)
	{
		if (fd->fixtureType == SHAPE_CIRCLE)
		{
			auto shape = PhysicsShapeCircle::create(fd->radius, PhysicsMaterial(0.0f, fd->elasticity, fd->friction), fd->center);
			shape->setGroup(fd->group);
			//            shape->setCategoryBitmask(fd->collisionType);
			body->addShape(shape);
		}
		else if (fd->fixtureType == SHAPE_POLYGON)
		{
			for (auto polygon : fd->polygons)
			{
				auto shape = PhysicsShapePolygon::create(polygon->vertices, polygon->numVertices, PhysicsMaterial(0.0f, fd->elasticity, fd->friction), fd->center);
				shape->setGroup(fd->group);
				//                shape->setCategoryBitmask(fd->collisionType);
				body->addShape(shape);
			}
		}
	}
	return body;
}
开发者ID:anchpop,项目名称:Knights-Ascension,代码行数:28,代码来源:PEShapeCache_X3_0.cpp

示例3: init

bool Monster::init()
{
	mutex = PTHREAD_MUTEX_INITIALIZER;
	status = DONE;
	auto snakeTexture = TextureCache::sharedTextureCache()->addImage(
			basic.getCString());
	float dWidth = snakeTexture->getContentSize().width / cntWidth;
	float dHeight = snakeTexture->getContentSize().height / cntHeight;

	this->setAnchorPoint(Vec2(0.5,32/dHeight));
	PhysicsBody *body = PhysicsBody::createBox(Size(60,60));
	body->setPositionOffset(Vec2(0,64/4-dHeight/4));
	body->setRotationEnable(false);
	body->setGravityEnable(false);
	body->setContactTestBitmask(0xffffffff);
	body->setCollisionBitmask(0xffffffff);
	this->setPhysicsBody(body);
	this->setTag(MONSTER);
	auto listener = EventListenerCustom::create("main_action",
			CC_CALLBACK_1(Monster::receive,this));
	_eventDispatcher->addEventListenerWithFixedPriority(listener, 1);
	return true;

	return false;
}
开发者ID:luchao0213,项目名称:workspace,代码行数:25,代码来源:Monster.cpp

示例4: addChild


//.........这里部分代码省略.........
    addChild(btn_2,5);
    QuestionButton* btn_3 = QuestionButton::create();
    btn_3->setObj(b3);
    addChild(btn_3,5);
    Btn_Standard* btn_4 = Btn_Standard::create();
    btn_4->setObj(b4);
    addChild(btn_4,5);
    Btn_Standard* btn_5 = Btn_Standard::create();
    btn_5->setObj(b5);
    addChild(btn_5,5);
    //给按钮设置问题 4个问题
    Btn_QuestionSelect* qbtn_1 = Btn_QuestionSelect::create();
    qbtn_1->setObj(q1);
    qbtn_1->setIBtnMainUI(mainui, btn_1);
    addChild(qbtn_1,8);
    Btn_QuestionSelect* qbtn_2 = Btn_QuestionSelect::create();
    qbtn_2->setObj(q2);
    qbtn_2->setIBtnMainUI(mainui, btn_2);
    addChild(qbtn_2,8);
    Btn_QuestionSelect* qbtn_3 = Btn_QuestionSelect::create();
    qbtn_3->setObj(q3);
    qbtn_3->setIBtnMainUI(mainui, btn_3);
    addChild(qbtn_3,8);
    Btn_QuestionSelect* qbtn_4 = Btn_QuestionSelect::create();
    qbtn_4->setObj(q4);
    qbtn_4->setIBtnMainUI(mainui, btn_4);
    addChild(qbtn_4,8);
    Btn_QuestionSelect* qbtn_5 = Btn_QuestionSelect::create();
    qbtn_5->setObj(q5);
    qbtn_5->setIBtnMainUI(mainui, btn_5);
    addChild(qbtn_5,8);
    ParticleSystemQuad* qp5 = root_level->getChildByName<ParticleSystemQuad*>("Particle_2");
    PhysicsBody* qpphy = PhysicsBody::createBox(Size(200.0f,10.0f));
    qpphy->setPositionOffset(Vec2(-100.0f, 0.0f));
    //火的碰撞掩码
    qpphy->setTag(PHY_TAG_KILL_FIRE);
    //设置触发 掩码
    qpphy->setContactTestBitmask(0x01);
    qpphy->setCollisionBitmask(0x02);
    qpphy->setDynamic(false);
    qp5->setPhysicsBody(qpphy);
    qp6 = root_level->getChildByName<ParticleSystemQuad*>("Particle_1");
    PhysicsBody* qpphy6 = PhysicsBody::createBox(Size(60.0f,60.0f));
    qpphy6->setPositionOffset(Vec2(0.0f, 0.0f));
    //火的碰撞掩码
    qpphy6->setTag(PHY_TAG_KILL_FIRE);
    //设置触发 掩码
    qpphy6->setContactTestBitmask(0x01);
    qpphy6->setCollisionBitmask(0x02);
    qpphy6->setDynamic(true);
    qpphy6->setRotationEnable(false);
    qp6->setPhysicsBody(qpphy6);
    //车变换位置
    mainui->setMovePosition(gound_8, gound_9,true);
    //添加怪物
    Scorpion_gw* scor = Scorpion_gw::create();
    scor->setObj(gound_11);
    scor->setMovePosition(gound_10,gound_12, 26.2f);
    addChild(scor);
    //弹簧
    Sprite* th = root_level->getChildByName<Sprite*>("tur0001_91");
    objSpring* ths = objSpring::create();
    ths->setPhysicsTag(600002);
    ths->setObj(th);
    addChild(ths);
    //弹簧
开发者ID:jian22446688,项目名称:DesertTour,代码行数:67,代码来源:Level_8.cpp


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