本文整理汇总了C++中PhysicsBody::getShape方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsBody::getShape方法的具体用法?C++ PhysicsBody::getShape怎么用?C++ PhysicsBody::getShape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsBody
的用法示例。
在下文中一共展示了PhysicsBody::getShape方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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);
}
}
示例3: callbackC
void LevelFifteen::callbackC(Node* sender)
{
auto visibleSize = Director::getInstance()->getVisibleSize();
auto pictureName = 1 + rand() % 27;
auto str = String::createWithFormat("%d.png", pictureName)->getCString();
auto ballTwo2 = Sprite::createWithSpriteFrameName(str);
ballTwo2->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height - 90));
PhysicsBody* ballBodyTwo = nullptr;
if (pictureName <= 9)
{
ballBodyTwo = PhysicsBody::createBox(ballTwo2->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT);
}
else if (pictureName > 9 && pictureName <= 18)
{
ballBodyTwo = PhysicsBody::createCircle(ballTwo2->getContentSize().width / 2.0f, PHYSICSBODY_MATERIAL_DEFAULT);
}
else if (pictureName > 18 && pictureName <= 21)
{
Vec2 vec[] = {
Vec2(-22.50000, 22.00000),
Vec2(24.00000, 10.00000),
Vec2(-10.00000, -24.00000)
};
ballBodyTwo = PhysicsBody::createPolygon(vec, 3);
}
else if (pictureName > 21 && pictureName <= 24)
{
Vec2 vec[] = {
Vec2(-15.50000, 15.00000),
Vec2(15.50000, 6.00000),
Vec2(-7.00000, -15.50000)
};
ballBodyTwo = PhysicsBody::createPolygon(vec, 3);
}
else if (pictureName > 24 && pictureName <= 27)
{
Vec2 vec[] = {
Vec2(-8.00000, 8.00000),
Vec2(7.50000, 3.00000),
Vec2(-4.00000, -7.50000)
};
ballBodyTwo = PhysicsBody::createPolygon(vec, 3);
}
//是否设置物体为静态
//ballBodyTwo->setDynamic(false);
ballBodyTwo->getShape(0)->setRestitution(1.0f);
ballBodyTwo->getShape(0)->setFriction(0.0f);
ballBodyTwo->getShape(0)->setDensity(1.0f);
ballBodyTwo->setGravityEnable(false);
ballBodyTwo->setCategoryBitmask(2);// 分类掩码
ballBodyTwo->setCollisionBitmask(1 | 2 | 4 | 8);// 碰撞掩码
ballBodyTwo->setContactTestBitmask(1 | 8);// 接触测试掩码
ballBodyTwo->addMass(1000.0f);
int flag = CCRANDOM_0_1() * 2;
auto num = 0;
switch (flag)
{
case 0:
num = -1;
break;
case 1:
num = 1;
break;
default:
break;
}
auto force1 = Vec2(CCRANDOM_0_1()*10000.0f*num, -300000.0f);
ballBodyTwo->applyImpulse(force1);
ballTwo2->setPhysicsBody(ballBodyTwo);
this->addChild(ballTwo2);
}
示例4: init
bool GameLayer::init() {
if (!Layer::init()) {
return false;
}
this->score = 0;
this->gameStatus = GameStatus::GAME_RUNNING;
this->bestScore = UserDefault::getInstance()->getIntegerForKey(KEY);
visibleSize = Director::getInstance()->getVisibleSize();
//创建小鸟
this->bird = BirdSprite::getInstance();
this->bird->createBird();
//创建物理属性
PhysicsBody *body = PhysicsBody::createCircle(15);
//设置为受到重力影响的动态刚体
body->setDynamic(true);
//设置线性阻尼
body->setLinearDamping(0.0f);
//设置刚体是否受物理世界重力的影响
body->setGravityEnable(false);
//设置形状的恢复系数
//body->getShape(0)->setRestitution(0.0f);
body->getShape(0)->setDensity(1.0f);
//设置所属种类的掩码值
body->setCategoryBitmask(BIRD_MASK);
body->setCollisionBitmask(BIRD_MASK | OBST_MASK);
body->setContactTestBitmask(BIRD_MASK | OBST_MASK);
this->bird->setPhysicsBody(body);
this->bird->setPosition(visibleSize.width / 3, visibleSize.height / 2);
this->bird->idle();
this->bird->fly();
this->addChild(this->bird, 2);
//添加陆地物理属性
auto land = Node::create();
landHeight = BackgroundLayer::getLandHeight();
auto landBody = PhysicsBody::createBox(Size(visibleSize.width, landHeight));
landBody->getShape(0)->setRestitution(0.0f);
landBody->setDynamic(false);
landBody->setGravityEnable(false);
landBody->setCategoryBitmask(OBST_MASK);
landBody->setCollisionBitmask(BIRD_MASK | OBST_MASK);
landBody->setContactTestBitmask(BIRD_MASK | OBST_MASK);
land->setPhysicsBody(landBody);
land->setPosition(visibleSize.width / 2, landHeight / 2);
this->addChild(land, 10);
//添加碰撞监听
auto contactListener = EventListenerPhysicsContact::create();
contactListener->onContactBegin = CC_CALLBACK_1(GameLayer::onContactBegin, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);
this->createPips();
this->scheduleUpdate();
this->schedule(schedule_selector(GameLayer::scrollPipe), 0.01f);
return true;
}
示例5: init
bool HelloWorld::init(PhysicsWorld* world,int _level)
{
if ( !Layer::init() )
{
return false;
}
level = _level;
//NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(HelloWorld::setLevel), "selectedLevel", NULL);
dispatcher = Director::getInstance()->getEventDispatcher();
preLoadMusic();
playBgMusic();
m_world = world;
//m_world->setAutoStep(false);
m_world->setGravity(Vect(0,-grivity));
this->setAnchorPoint(Point(0,0));
winSize = Director::getInstance()->getWinSize();
visibleSize = Director::getInstance()->getVisibleSize();
origin = Director::getInstance()->getVisibleOrigin();
auto map1path = String::createWithFormat("%s%d%s","images/level",level,"/bg.png");
map1 = Sprite::create(map1path->getCString());
map1->setPosition(map1->getContentSize().width/2+origin.x, map1->getContentSize().height/2+origin.y);
this->addChild(map1,1,MAP1_TAG);
auto map2path = String::createWithFormat("%s%d%s", "images/level", level, "/bg.png");
map2 = Sprite::create(map2path->getCString());
map2->setPosition(map1->getContentSize().width+map2->getContentSize().width/2+origin.x, map2->getContentSize().height/2+origin.y);
this->addChild(map2,1,MAP2_TAG);
Sprite* edge1 = Sprite::create();
edge1->setContentSize(visibleSize);
PhysicsBody* edgeBody1 = PhysicsBody::createEdgeBox(visibleSize);
edgeBody1->setDynamic(false);
edgeBody1->setGravityEnable(false);
edgeBody1->setMass(100000.0f);
edgeBody1->getShape(0)->setRestitution(0.0f);
edgeBody1->setContactTestBitmask(0xFF);
edgeBody1->setCategoryBitmask(0x04);
edgeBody1->setCollisionBitmask(0xFF);
edgeBody1->getShape(0)->setTag(EDGE_TAG);
edge1->setPhysicsBody(edgeBody1);
edge1->setPosition(visibleSize.width/2,visibleSize.height/2);
addChild(edge1,1,EDGEONE_TAG);
Sprite* edge = Sprite::create();
edge->setContentSize(visibleSize);
PhysicsBody* edgeBody = PhysicsBody::createEdgeBox(Size(visibleSize.width,visibleSize.height/6));
edgeBody->setDynamic(false);
edgeBody->setGravityEnable(false);
edgeBody->setMass(100000.0f);
edgeBody->getShape(0)->setRestitution(0.0f);
edgeBody->setContactTestBitmask(0xFF);
edgeBody->setCategoryBitmask(0x04);
edgeBody->setCollisionBitmask(0xFF);
edgeBody->getShape(0)->setTag(EDGE_TAG);
edge->setPhysicsBody(edgeBody);
edge->setPosition(visibleSize.width / 2, visibleSize.height / 12);
addChild(edge, 1, EDGE_TAG);
Sprite* floor = Sprite::create();
PhysicsBody* floorBody = PhysicsBody::createEdgeSegment(Point(0, visibleSize.height / 10), Point(visibleSize.width, visibleSize.height / 10));
floorBody->setDynamic(false);
floorBody->setGravityEnable(false);
floorBody->getShape(0)->setRestitution(0.0f);
floorBody->setMass(100000.0f);
floorBody->setCategoryBitmask(0x0003);
floorBody->setContactTestBitmask(0x0003);
floorBody->setCollisionBitmask(0x0001);
floor->setPosition(0, visibleSize.height / 10);
floor->setPhysicsBody(floorBody);
//this->addChild(floor,2,FLOOR_TAG);
setEnemyFrameNumber();
setPlayerFrameNumber();
initDamage();
player1 = new player();
auto playerPath = String::createWithFormat("%s%d%s", "images/level", level, "/player.png");
player1->sprite = Sprite::create(playerPath->getCString());
PhysicsBody* playerBody = PhysicsBody::createBox(player1->sprite->getContentSize());
playerBody->setRotationEnable(false);
playerBody->getShape(0)->setRestitution(0.0f);
playerBody->getShape(0)->setFriction(0.8f);
playerBody->setMass(player1->mass);
playerBody->setCollisionBitmask(0x04);
playerBody->setCategoryBitmask(0x01);
playerBody->setContactTestBitmask(0xFF);
playerBody->getShape(0)->setTag(PLAYER_TAG);
player1->sprite->setPhysicsBody(playerBody);
player1->sprite->setPosition(player1->sprite->getContentSize().width/2+5, floor->getPositionY()+player1->sprite->getContentSize().height*3);
addChild(player1->sprite,2,PLAYER_TAG);
preLoadAnimation();
auto backItem = MenuItemImage::create("images/CloseNormal.png", "images/CloseSelected.png", CC_CALLBACK_0(HelloWorld::backToChoseLevel, this));
//auto pauseItem = MenuItemImage::create("CloseNormal.png", "CloseSelected.png", CC_CALLBACK_0(HelloWorld::pauseScene, this));
auto popupItem = MenuItemImage::create("images/CloseNormal.png", "images/CloseSelected.png", CC_CALLBACK_0(HelloWorld::toPopup, this));
//pauseItem->setPosition(-backItem->getContentSize().width,0);
//.........这里部分代码省略.........