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


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

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


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

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

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

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

示例4: init

bool Witch::init()
{ 
	mWitch = CCSprite::createWithSpriteFrameName(Tex::Player_0);
	this->addChild(mWitch);
	CCLOG("Witch Width:%f", mWitch->getContentSize().width);
	mWitch->setPosition(0, 0);
	

	PhysicsBody *body = PhysicsBody::create();
	body->setTag(1);
	this->setPhysicsBody(body);
	body->addShape(PhysicsShapeBox::create(Size(mWitch->getContentSize().width, mWitch->getContentSize().height)));
	
	body->setDynamic(true);
	body->setLinearDamping(0.0f);
	body->setGravityEnable(false); 
	
	return true;
}
开发者ID:sandfresh,项目名称:HalloweenJump,代码行数:19,代码来源:Witch.cpp

示例5: switch

BoundWall::BoundWall(WallType type, Size screenSize)
{
    PhysicsBody* body = nullptr;
    switch (type)
    {
    case UP:
        this->setAnchorPoint(Vec2(0.5f, 0));
        this->setPosition(Vec2(screenSize.width / 2, screenSize.height));
        body = PhysicsBody::createBox(Size(screenSize.width,5), PhysicsMaterial(1, 0, 0));
        break;
    case DOWN:
        this->setAnchorPoint(Vec2(0.5f, 1));
        this->setPosition(Vec2(screenSize.width / 2, 0));
        body = PhysicsBody::createBox(Size(screenSize.width, 5), PhysicsMaterial(1, 0, 0));
        break;
    case LEFT:
        this->setAnchorPoint(Vec2(1, 0.5f));
        this->setPosition(Vec2(0, screenSize.height / 2));
        body = PhysicsBody::createBox(Size(5, screenSize.height), PhysicsMaterial(1, 0, 0));
        break;
    case RIGHT:
        this->setAnchorPoint(Vec2(0, 0.5f));
        this->setPosition(Vec2(screenSize.width, screenSize.height / 2));
        body = PhysicsBody::createBox(Size(5, screenSize.height), PhysicsMaterial(1, 0, 0));
        break;
    default:
        break;
    }

    body->setGravityEnable(false);
    body->setDynamic(false);
    body->setTag(Tags::GROUND);
    body->setCollisionBitmask(true);
    body->setContactTestBitmask(true);
    this->setPhysicsBody(body);
}
开发者ID:HuyenPhuong,项目名称:mini,代码行数:36,代码来源:BoundWall.cpp

示例6: addChild

// on "init" you need to initialize your instance
bool Level_5::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() ){
        return false;
    }
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 visiblePoint = Director::getInstance()->getVisibleOrigin();
    auto root_level_5 = CSLoader::createNode("Scene/LevelScene/Level_5.csb");
    root_level_5->setTag(100001);
    this->addChild(root_level_5);
    //设置物理 空心世界
    PhysicsBody* psworld =PhysicsBody::createEdgeBox(Size(visibleSize.width,visibleSize.height*1.2),PHYSICSBODY_MATERIAL_DEFAULT,2);
    psworld->setCategoryBitmask(0x01);
    psworld->setCollisionBitmask(0x01);
    psworld->setContactTestBitmask(0x01);
    root_level_5->setPhysicsBody(psworld);
    //火把
    Node* hb1 = root_level_5->getChildByName<Node*>("FileNode_1");
    //火把
    Node* hb2 = root_level_5->getChildByName<Node*>("FileNode_1_0");
    fire_x* fhb1 = fire_x::create();
    fhb1->setObject(hb1);
    addChild(fhb1);
    fire_x* fhb2 = fire_x::create();
    fhb2->setObject(hb2);
    addChild(fhb2);
    //完成退出
    Sprite* exitl5 = root_level_5->getChildByName<Sprite*>("img_next_27");
    //主要车
    Sprite* carl5 = root_level_5->getChildByName<Sprite*>("img_maincarbody_1");
    //按钮一
    Sprite* btnl5_1 = root_level_5->getChildByName<Sprite*>("btn_010001_50");
    //按钮二
    anim_l5_2 = root_level_5->getChildByName<Node*>("FileNode_2_kill");
    //按钮三
    Sprite* btnl5_3 = root_level_5->getChildByName<Sprite*>("btn_010001_50_0");
    //问题1
    Sprite* questionl4_1 = root_level_5->getChildByName<Sprite*>("anim_question0001_51_0");
    //问题2
    Sprite* questionl4_2 = root_level_5->getChildByName<Sprite*>("anim_question0001_51");
    //问题3
    Sprite* questionl4_3 = root_level_5->getChildByName<Sprite*>("anim_question0001_25");
    //怪物a
    Sprite* monsterl5_0 = root_level_5->getChildByName<Sprite*>("monster_18");
    //怪物
    Sprite* monsterl5_1 = root_level_5->getChildByName<Sprite*>("anim_guaiwu_1");
    //按钮二
    Sprite* monsterl5_2 = root_level_5->getChildByName<Sprite*>("btn_010001_22_0");
    //按钮二
    Sprite* monsterl5_3 = root_level_5->getChildByName<Sprite*>("btn_010001_22_0_0");
    //地面按钮
    Sprite* btngroundl5_2 = root_level_5->getChildByName<Sprite*>("btn_dicar0001_9");
    //地面右上
    Sprite* groundl5_1 = root_level_5->getChildByName<Sprite*>("td4_47_2");
    //地面下
    Sprite* groundl5_2 = root_level_5->getChildByName<Sprite*>("d1_3");
    //地面左上
    Sprite* groundl5_5 = root_level_5->getChildByName<Sprite*>("td4_47_1");
    //地面右上
    Sprite* groundl5_6 = root_level_5->getChildByName<Sprite*>("td4_47_3");
    //弹簧
    Sprite* sprs = root_level_5->getChildByName<Sprite*>("tur0001_47");
    //怪物门
    Sprite* gate = root_level_5->getChildByName<Sprite*>("d3_5");
    //yidong
    Sprite* move_17 = root_level_5->getChildByName<Sprite*>("move_17");
    //电网
    ParticleSystemQuad* particle_1 = root_level_5->getChildByName<ParticleSystemQuad*>("Particle_1");
    particle_1->setContentSize(Size(26.0f,200.0f));
    ToolsFunction::setPhyDynamicSpriteBox(move_17);
    ToolsFunction::setPhyDynamicSpriteBox(groundl5_1);
    ToolsFunction::setPhyDynamicSpriteBox(groundl5_2);
    ToolsFunction::setPhyDynamicSpriteBox(groundl5_5);
    ToolsFunction::setPhyDynamicSpriteBox(groundl5_6);
    
    //设置刚体
    PhysicsBody* psworld2 =PhysicsBody::createBox(Size(particle_1->getContentSize().width,particle_1->getContentSize().height));
    psworld2->setPositionOffset(Vec2(-13.0f, -110.0f));
    //火的碰撞掩码
    psworld2->setTag(PHY_TAG_KILL_FIRE);
    //设置触发 掩码
    psworld2->setContactTestBitmask(0x01);
    psworld2->setCollisionBitmask(0x02);
    psworld2->setDynamic(false);
    particle_1->setPhysicsBody(psworld2);
    
    //添加地面按钮
    Btn_Ground_1* btngr = Btn_Ground_1::create();
    btngr->setObj(btngroundl5_2);
    addChild(btngr);
    
    //创建主要UI界面
    mainui = MainUI::create();
    auto maincar_r = MainCar_R::create();
    mainui->setCar_R(maincar_r);
    maincar_r->setMainUI(mainui);
    maincar_r->setObj(carl5);
//.........这里部分代码省略.........
开发者ID:jian22446688,项目名称:DesertTour,代码行数:101,代码来源:Level_5.cpp

示例7: clipPoly

void FruitCutNinjaScene::clipPoly(PhysicsShapePolygon* shape, Point normal, float distance)
{
    PhysicsBody* body = shape->getBody();
    int count = shape->getPointsCount();
    int pointsCount = 0;
    Point* points = new Point[count + 1];
    
    Vector2dVector vcPoints;
    vcPoints.clear();
    Vector2d v2Point(0, 0);
    
    for (int i=0, j=count-1; i<count; j=i, ++i)
    {
        Point a = body->local2World(shape->getPoint(j));
        float aDist = a.dot(normal) - distance;
        
        if (aDist < 0.0f)
        {
            points[pointsCount] = a;
            ++pointsCount;
        }
        
        Point b = body->local2World(shape->getPoint(i));
        float bDist = b.dot(normal) - distance;
        
        if (aDist*bDist < 0.0f)
        {
            float t = std::fabs(aDist)/(std::fabs(aDist) + std::fabs(bDist));
            Vec2 v2Tmp = a.lerp(b, t);
            points[pointsCount] = v2Tmp;
            ++pointsCount;
        }
    }
    
    Point center = PhysicsShape::getPolyonCenter(points, pointsCount);
    
    for (int i = 0; i < pointsCount; i++)
    {
        points[i] = body->world2Local(points[i]);
        vcPoints.push_back(Vector2d(points[i].x, points[i].y));
    }
    
    PhysicsBody* polyon = PhysicsBody::createPolygon(points, pointsCount);
    
    PRFilledPolygon* pNode = (PRFilledPolygon*)(body->getNode());
    std::string sName = pNode->getTextureName();
    //auto texture = Director::getInstance()->getTextureCache()->addImage("pineapple.png");
    PRFilledPolygon *filledPolygon = PRFilledPolygon::filledPolygonWithPointsAndTexture(vcPoints, sName.c_str());
    filledPolygon->setPhysicsBody(polyon);
    filledPolygon->setPosition(body->getPosition() + normal * -40);
    filledPolygon->getPhysicsBody()->setTag(_sliceTag);
    filledPolygon->getPhysicsBody()->setGravityEnable(false);
    
    polyon->setVelocity(body->getVelocityAtWorldPoint(center));
    polyon->setAngularVelocity(body->getAngularVelocity());
    polyon->setTag(_sliceTag);
    //polyon->applyImpulse(normal * -100);
    addChild(filledPolygon, 80);
    
    /*
    CPolygonSprite* pSprite = CPolygonSprite::create();
    pSprite->initWithFile("pineapple.png", polyon, false);
    pSprite->setPosition(body->getPosition());
    polyon->setTag(_sliceTag);
    addChild(pSprite);
    */
    
    /*
    Node* node = Node::create();
    PhysicsBody* polyon = PhysicsBody::createPolygon(points, pointsCount, PHYSICSBODY_MATERIAL_DEFAULT, -center);
    node->setPosition(center);
    node->setPhysicsBody(polyon);
    polyon->setVelocity(body->getVelocityAtWorldPoint(center));
    polyon->setAngularVelocity(body->getAngularVelocity());
    polyon->setTag(_sliceTag);
    addChild(node);
    */
    delete[] points;
}
开发者ID:GitofThunder,项目名称:gitskills,代码行数:79,代码来源:FruitCutNinjaScene.cpp

示例8: clipPoly

void CCutScene::clipPoly(PhysicsShapePolygon* shape, Point normal, float distance)
{
    PhysicsBody* body = shape->getBody();
    int count = shape->getPointsCount();
    int pointsCount = 0;
    Point* points = new Point[count + 1];
    
    Vector2dVector vcPoints;
    vcPoints.clear();
    Vector2d v2Point(0, 0);
    
    for (int i=0, j=count-1; i<count; j=i, ++i)
    {
        Point a = body->local2World(shape->getPoint(j));
        float aDist = a.dot(normal) - distance;
        
        if (aDist < 0.0f)
        {
            points[pointsCount] = a;
            ++pointsCount;
        }
        
        Point b = body->local2World(shape->getPoint(i));
        float bDist = b.dot(normal) - distance;
        
        if (aDist*bDist < 0.0f)
        {
            float t = std::fabs(aDist)/(std::fabs(aDist) + std::fabs(bDist));
            Vec2 v2Tmp = a.lerp(b, t);
            points[pointsCount] = v2Tmp;
            ++pointsCount;
        }
    }
    
    Point center = PhysicsShape::getPolyonCenter(points, pointsCount);
    
    for (int i = 0; i < pointsCount; i++)
    {
        points[i] = body->world2Local(points[i]);
        vcPoints.push_back(Vector2d(points[i].x, points[i].y));
    }
    
    PhysicsBody* polyon = PhysicsBody::createPolygon(points, pointsCount);
    
    CFoodCut* pNode = (CFoodCut*)(body->getNode());
    std::vector<int> vMaterials;
    vMaterials.clear();
    vMaterials = pNode->getMaterials();
    MATERIAL_ID eId = MI_MAX;
    if (vMaterials.size() != 0)
    {
        eId = (MATERIAL_ID)vMaterials[0];
    }
    
    CFoodCut *filledPolygon = CFoodCut::create(eId, vcPoints, pNode->getPanziIndex(), pNode->getTouchedIndex());
    filledPolygon->setPhysicsBody(polyon);
    int nTmp = rand() % 50 + 50;
    int nTmpRotate = rand() % 30 - 60;
    filledPolygon->setPosition(body->getPosition());
    //filledPolygon->setRotation(filledPolygon->getRotation() + nTmpRotate);
    filledPolygon->getPhysicsBody()->setTag(_sliceTag);
    filledPolygon->getPhysicsBody()->setGravityEnable(false);
    
    
    polyon->setVelocity(body->getVelocityAtWorldPoint(center));
    //polyon->setAngularVelocity(body->getAngularVelocity());
    polyon->setTag(_sliceTag);
    
    float fMass = polyon->getMass();
    float fV = 80;
    float fImpulse = fMass * fV;
    float fTmpX = (float)(Random() % 30) / 100.0f - 0.15f;
    float fTmpY = (float)(rand() % 30) / 100.0f - 0.15f;
    polyon->applyImpulse((normal + Vec2(fTmpX, fTmpY)) * -fImpulse);
    polyon->setLinearDamping(0.8f);
    addChild(filledPolygon, 80);
    filledPolygon->setBirthTime(getCurTime());
    m_vCutFoods.push_back(filledPolygon);
    m_nSliceCount ++;
    delete[] points;
}
开发者ID:GitofThunder,项目名称:gitskills,代码行数:81,代码来源:CutScene.cpp

示例9: addChild

// on "init" you need to initialize your instance
bool Level_8::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 visiblePoint = Director::getInstance()->getVisibleOrigin();
    root_level = CSLoader::createNode("Scene/LevelScene/Level_8.csb");
    root_level->setTag(100001);
    this->addChild(root_level);
    //设置物理 空心世界
    PhysicsBody* psworld =PhysicsBody::createEdgeBox(visibleSize*1.5,PHYSICSBODY_MATERIAL_DEFAULT,2);
    psworld->setCategoryBitmask(0x01);
    psworld->setCollisionBitmask(0x01);
    psworld->setContactTestBitmask(0x01);
    root_level->setPhysicsBody(psworld);
    //车
    Sprite* maincar = root_level->getChildByName<Sprite*>("img_maincarbody_17");
    //退出
    Sprite* mainexit = root_level->getChildByName<Sprite*>("img_next_14");
    //创建主要UI界面
    mainui = MainUI::create();
    auto maincar_r = MainCar_R::create();
    mainui->setCar_R(maincar_r);
    maincar_r->setMainUI(mainui);
    maincar_r->setObj(maincar);
    addChild(maincar_r,10);
    addChild(mainui,3000);
    //退出
    Exit* eit = Exit::create();
    eit->setObj(mainexit);
    addChild(eit);
    //添加地面的刚体
    Sprite* gound_1 = root_level->getChildByName<Sprite*>("l8_gound_1_1");
    Sprite* gound_2 = root_level->getChildByName<Sprite*>("l8_gound_2_1");
    Sprite* gound_3 = root_level->getChildByName<Sprite*>("l8_gound_3_1");
    Sprite* gound_4 = root_level->getChildByName<Sprite*>("l8_gound_4_1");
    Sprite* gound_5 = root_level->getChildByName<Sprite*>("l8_gound_5_1");
    Sprite* gound_6 = root_level->getChildByName<Sprite*>("l8_gound_6_1");
    Sprite* gound_7 = root_level->getChildByName<Sprite*>("l8_gound_7_1");
    Sprite* gound_14 = root_level->getChildByName<Sprite*>("l8_gound_14_1");
    //////////////////////////////////////////////////////////////////////
    Sprite* gound_8 = root_level->getChildByName<Sprite*>("l8_gound_8_1");
    Sprite* gound_9 = root_level->getChildByName<Sprite*>("l8_gound_9_1");
    Sprite* gound_10 = root_level->getChildByName<Sprite*>("l8_gound_10_1");
    Sprite* gound_11 = root_level->getChildByName<Sprite*>("l8_gound_11_1");
    Sprite* gound_12 = root_level->getChildByName<Sprite*>("l8_gound_12_1");
    Sprite* gound_13 = root_level->getChildByName<Sprite*>("l8_gound_13_1");
    ToolsFunction::setPhyDynamicSpriteBox(gound_1);
    ToolsFunction::setPhyDynamicSpriteBox(gound_2);
    ToolsFunction::setPhyDynamicSpriteBox(gound_3);
    ToolsFunction::setPhyDynamicSpriteBox(gound_4);
    ToolsFunction::setPhyDynamicSpriteBox(gound_5);
    ToolsFunction::setPhyDynamicSpriteBox(gound_6);
    ToolsFunction::setPhyDynamicSpriteBox(gound_7);
    ToolsFunction::setPhyDynamicSpriteBox(gound_14);
    //四个二维数组点 组成多边形
    Vec2 pa[3] = {
        Vec2(-gound_13->getContentSize().width/2,-gound_13->getContentSize().height/2),
        Vec2(-gound_13->getContentSize().width/2+2,gound_13->getContentSize().height/2-2),
        Vec2(-gound_13->getContentSize().width/3+120 ,-gound_13->getContentSize().height/2)};
    auto aa = PhysicsBody::createPolygon(pa, 3);
//    aa->setCategoryBitmask(0x03);
//    aa->setCollisionBitmask(0x03);
//    aa->setContactTestBitmask(0x03);
    aa->setDynamic(false);
    //aa->setLinearDamping(5000.0f);
    gound_13->setPhysicsBody(aa);
    //按钮 1
    Button* b1 = root_level->getChildByName<Button*>("Button_1");
    Button* b2 = root_level->getChildByName<Button*>("Button_2");
    Button* b3 = root_level->getChildByName<Button*>("Button_3");
    Sprite* b4 = root_level->getChildByName<Sprite*>("Button_4");
    Sprite* b5 = root_level->getChildByName<Sprite*>("Button_5");
    //按钮问题
    Sprite* q1 = root_level->getChildByName<Sprite*>("question_1");
    Sprite* q2 = root_level->getChildByName<Sprite*>("question_2");
    Sprite* q3 = root_level->getChildByName<Sprite*>("question_3");
    Sprite* q4 = root_level->getChildByName<Sprite*>("question_4");
    Sprite* q5 = root_level->getChildByName<Sprite*>("question_5");
    //创建颜色按钮 4个按钮
    QuestionButton* btn_1 = QuestionButton::create();
    btn_1->setObj(b1);
    addChild(btn_1,5);
    QuestionButton* btn_2 = QuestionButton::create();
    btn_2->setObj(b2);
    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);
//.........这里部分代码省略.........
开发者ID:jian22446688,项目名称:DesertTour,代码行数:101,代码来源:Level_8.cpp

示例10: addChild

// on "init" you need to initialize your instance
bool Level_2::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 visiblePoint = Director::getInstance()->getVisibleOrigin();
    
    auto root_level_2 = CSLoader::createNode("Scene/LevelScene/Level_2.csb");
    root_level_2->setTag(100001);
    this->addChild(root_level_2);
    
    
    //设置物理 空心世界
    PhysicsBody* psworld =PhysicsBody::createEdgeBox(visibleSize*1.5,PHYSICSBODY_MATERIAL_DEFAULT,2);
    psworld->setCategoryBitmask(0x01);
    psworld->setCollisionBitmask(0x01);
    psworld->setContactTestBitmask(0x01);
    root_level_2->setPhysicsBody(psworld);
    
    
    //素材火把添加;
    auto hb1 = root_level_2->getChildByName<Sprite*>("FileNode_1_0");
    auto hb2 = root_level_2->getChildByName<Sprite*>("FileNode_1");
    
    //添加一个火把
    auto ohb1 = fire_x::create();
    ohb1->setObject(hb1);
    root_level_2->addChild(ohb1);
    //添加二个火把
    auto ohb2 = fire_x::create();
    ohb2->setObject(hb2);
    root_level_2->addChild(ohb2);
    
    //设置 物理世界里面的 静态 刚体
    Sprite* phys1 = root_level_2->getChildByName<Sprite*>("img_ground_04");
    Sprite* phys2 = root_level_2->getChildByName<Sprite*>("img_ground_05_25");
    Sprite* phys3 = root_level_2->getChildByName<Sprite*>("img_ground_06");
    ToolsFunction::setPhyDynamicSpriteBox(phys1);
    ToolsFunction::setPhyDynamicSpriteBox(phys2);
    ToolsFunction::setPhyDynamicSpriteBox(phys3);

    //设置多边形的 物理刚体
    Sprite* phys4 = root_level_2->getChildByName<Sprite*>("img_ground_03");
    //四个二维数组点 组成多边形
    Vec2 pa[4] = {
        Vec2(-phys4->getContentSize().width/2,-phys4->getContentSize().height/2),
        Vec2(-phys4->getContentSize().width/2,phys4->getContentSize().height/2-2),
        Vec2(-phys4->getContentSize().width/3+150 ,phys4->getContentSize().height/2-2),
        Vec2(phys4->getContentSize().width/2,-phys4->getContentSize().height/2)};
    auto aa = PhysicsBody::createPolygon(pa, 4);
    aa->setDynamic(false);
    aa->setLinearDamping(5000.0f);
    phys4->setPhysicsBody(aa);
    
    
    //退出的
    Sprite* ni1 = root_level_2->getChildByName<Sprite*>("img_next_27");
    auto nexit = Exit::create();
    nexit->setObj(ni1);
    addChild(nexit);

    //火的精灵
    Sprite* fire1 = root_level_2->getChildByName<Node*>("FileNode_6")->getChildByName<Sprite*>("anim_huo0001_1");
    //设置刚体
    PhysicsBody* psworld2 =PhysicsBody::createBox(Size(fire1->getContentSize().width-40,fire1->getContentSize().height-20));
    //火的碰撞掩码
    psworld2->setTag(PHY_TAG_KILL_FIRE);
    //设置触发 掩码
    psworld2->setContactTestBitmask(0x01);
    psworld2->setCollisionBitmask(0x02);
    psworld2->setDynamic(false);
    fire1->setPhysicsBody(psworld2);
    //帧动画 不能使用精灵运行帧动画
    auto fireh1 = CSLoader::createTimeline("Node/animation/L2_fire.csb");
    fireh1->gotoFrameAndPlay(0, 33, true);
    root_level_2->runAction(fireh1);

    
    //获取车的位置
    Sprite* mycar = root_level_2->getChildByName<Sprite*>("img_maincarbody_9");
    //创建主要UI界面
    mainui = MainUI::create();
    auto maincar = MainCar_R::create();
    mainui->setCar_R(maincar);
    maincar->setMainUI(mainui);
    maincar->setObj(mycar);
    addChild(maincar);
    addChild(mainui,3000);
    
    //添加第一个怪物
    //FileNode_5
    
    Node* jsa1 = root_level_2->getChildByName<Node*>("FileNode_5");
    
//.........这里部分代码省略.........
开发者ID:jian22446688,项目名称:DesertTour,代码行数:101,代码来源:Level_2.cpp


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