本文整理汇总了C++中PhysicsBody::setEnabled方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsBody::setEnabled方法的具体用法?C++ PhysicsBody::setEnabled怎么用?C++ PhysicsBody::setEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsBody
的用法示例。
在下文中一共展示了PhysicsBody::setEnabled方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
/** 碰撞开始事件
* @2015/12/16 11:28
*/
bool Level_1::onCollisionBegin(const cocos2d::PhysicsContact& contact)
{
PhysicsBody* bodyA = contact.getShapeA()->getBody();
PhysicsBody* bodyB = contact.getShapeB()->getBody();
PhysicsBody* temp =nullptr;
//log("A:%d B:%d",bodyA->getTag(),bodyB->getTag());
if(bodyA->getTag() == 555555)
{
temp = bodyB;
bodyB = bodyA;
bodyA = temp;
}
if(bodyB->getTag() == 555555)
{
//log("A:%d",bodyA->getTag());
// 100001 物理世界
// 555555 主要车的
// 300001 悬浮的物体
// 400001 第一关的怪物
// 600001 弹簧的物体
if (bodyA->getTag()== 400001)
{
MainCar_R* car =(MainCar_R*)bodyB->getNode()->getParent()->getParent();
//car->removeFromParent();
car->setBodyEnable();
}
switch (bodyA->getTag()) {
case 400001:
log("第一关的怪物");
bodyB->setEnabled(false);
break;
case 300001:
log("悬浮的物体");
break;
case 600001:
log("弹簧的物体");
break;
default:
break;
}
}
return true;
}
示例2: addChild
//.........这里部分代码省略.........
Btn_Standard* bs3 = Btn_Standard::create();
bs3->setObj(btnl5_3);
addChild(bs3,30);
Btn_QuestionSelect* qbs4 = Btn_QuestionSelect::create();
qbs4->setObj(questionl4_3);
qbs4->setIBtnMainUI(mainui, bs3);
addChild(qbs4,30);
Layer* dlyer = Layer::create();
dlyer->addChild(groundl5_5);
addChild(dlyer);
//怪物移动
guaiwu_js* gu = guaiwu_js::create();
gu->setGuanwu(monsterl5_1);
gu->setMovePosition(monsterl5_2, monsterl5_3, 20.0f);
addChild(gu);
PhysicsBody* gua = PhysicsBody::createBox(monsterl5_0->getContentSize());
gua->setTag(400030);
gua->setRotationEnable(false);
gua->setCategoryBitmask(0x01);
gua->setCollisionBitmask(0x02);
gua->setContactTestBitmask(0x01);
gua->setDynamic(true);
monsterl5_0->setPhysicsBody(gua);
//添加力度
bs2->getBtn()->addTouchEventListener([=](Ref* reft, Widget::TouchEventType type)
{
if (type==Widget::TouchEventType::ENDED) {
//bs2->PlayEffect();
//spr->addForce(Vec2(1000.0f, 1500.0f));
if (ismove) {
auto moveto = MoveTo::create(0.8f, Vec2(384.2f, move_17->getPosition().y));
move_17->runAction(moveto);
ismove = false;
}else{
auto moveto = MoveTo::create(0.8f, Vec2(159.2f, move_17->getPosition().y));
move_17->runAction(moveto);
ismove = true;
}
}
});
//关门
bs3->getBtn()->addTouchEventListener([=](Ref* reft, Widget::TouchEventType type)
{
if (type==Widget::TouchEventType::ENDED) {
bs2->PlayEffect();
auto scal = ScaleTo::create(1.0f, -1, 1);
gate->runAction(scal);
gua->setEnabled(false);
}
});
//地面按钮
btngr->onCallbackTest_2([=]()
{
if (particle_1) {
particle_1->setVisible(false);
particle_1->getPhysicsBody()->setEnabled(false);
}
});
//怪物动画刚体
Sprite* sprsphys = root_level_5->getChildByName<Sprite*>("btn_010001_22_1");
sprsphys->setVisible(false);
PhysicsBody* guaup = PhysicsBody::createBox(Size(sprsphys->getContentSize().width*1.5f,sprsphys->getContentSize().height));
guaup->setTag(PHY_TAG_KILL_UP);
guaup->setRotationEnable(false);
guaup->setCategoryBitmask(0x01);
guaup->setCollisionBitmask(0x02);
guaup->setContactTestBitmask(0x01);
guaup->setDynamic(true);
sprsphys->setPhysicsBody(guaup);
//播放怪物动画
anim = CSLoader::createTimeline("Node/level_animation/l5_updown.csb");
anim->gotoFrameAndPlay(0, 320, true);
root_level_5->runAction(anim);
//怪物下来
anim->addFrameEndCallFunc(29, "a", [=]()
{
guaup->setEnabled(true);
});
//怪物下来
anim->addFrameEndCallFunc(30, "b", [=]()
{
guaup->setEnabled(true);
});
//怪物下来
anim->addFrameEndCallFunc(74, "c", [=]()
{
guaup->setEnabled(false);
});
//怪物下来
anim->addFrameEndCallFunc(75, "d", [=]()
{
guaup->setEnabled(false);
});
scheduleUpdate();
return true;
}
示例3: addChild
//.........这里部分代码省略.........
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");
Sprite* psa1 = root_level_2->getChildByName<Sprite*>("btn_010001_59_0_0");
Sprite* psa2 = root_level_2->getChildByName<Sprite*>("btn_010001_59_0_0_0");
Sprite* psa3 = root_level_2->getChildByName<Sprite*>("btn_010001_59_2");
psa3->setVisible(false);
//第一个怪物
guaiwu_js* gw = guaiwu_js::create();
gw->setGuanwu(jsa1);
gw->setMovePosition(psa2, psa1, 18.0f);
addChild(gw);
//获取肉的精灵
Sprite* rm = root_level_2->getChildByName<Sprite*>("s22_43");
Sprite* r = root_level_2->getChildByName<Sprite*>("s23_50");
r->setVisible(false);
//设置肉的碰撞刚体
PhysicsBody* phyr = PhysicsBody::createBox(Size(r->getContentSize().width/3,r->getContentSize().height-3));
phyr->setEnabled(false);
//设置触发 掩码
phyr->setContactTestBitmask(0x01);
phyr->setCollisionBitmask(0x02);
phyr->setTag(400006);
phyr->setRotationEnable(true);
r->setPhysicsBody(phyr);
//phyr->setCategoryBitmask(0x01);
//火的按钮
Sprite* h1 = root_level_2->getChildByName<Sprite*>("btn_010001_59_1");
//实物的按钮
Sprite* h2 = root_level_2->getChildByName<Sprite*>("btn_010001_59");
//火的 问题 按钮
Sprite* qh1 = root_level_2->getChildByName<Sprite*>("anim_question0001_60_0");
//实物 问题 的按钮
Sprite* qh2 = root_level_2->getChildByName<Sprite*>("anim_question0001_60");
//按钮1
Btn_Standard* hba1 =Btn_Standard::create();
hba1->setObj(h1);
addChild(hba1);
hba1->getBtn()->addTouchEventListener([=](Ref* reft,Widget::TouchEventType type)
{
if (type ==Widget::TouchEventType::ENDED)
{
hba1->PlayEffect();
//控制火的按钮
fireh1->gotoFrameAndPause(36);
fire1->getPhysicsBody()->setEnabled(false);