本文整理汇总了C++中setDynamic函数的典型用法代码示例。如果您正苦于以下问题:C++ setDynamic函数的具体用法?C++ setDynamic怎么用?C++ setDynamic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setDynamic函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: switch
JSWindowVarObject::JSWindowVarObject( JSWindowObject *_obj, int _kind )
{
kind = _kind;
object = _obj;
switch ( kind )
{
case KIND_JSWindowStatus:
setName( "status" );
setDynamic( TRUE );
break;
case KIND_JSWindowTop:
setName( "top" );
setConst( TRUE );
break;
case KIND_JSWindowParent:
setName( "parent" );
setConst( TRUE );
break;
case KIND_JSWindowName:
setName( "name" );
setConst( TRUE );
setDynamic( TRUE );
break;
}
}
开发者ID:kthxbyte,项目名称:KDE1-Linaro,代码行数:26,代码来源:jscript.cpp
示例2: addGangti1
//第一关(添加5关的关卡刚体)
void GameLayer:: addGangti1(){
//木头
for (int i = 1; i<=9 ;i++ ) {
auto str = __String::createWithFormat("wood_%d",i);
Sprite* woods1 = node->getChildByName<Sprite*>(str->getCString());
// log("tag = %d",woods1->getTag());
if (woods1->getTag() ==5) {
auto body = PhysicsBody::createBox(woods1->getContentSize());
body->setDynamic(false);
body->getShape(0)->setRestitution(1);//反弹力
body->getShape(0)->setFriction(0);//摩擦力
woods1->setPhysicsBody(body);
woods1->getPhysicsBody()->setContactTestBitmask(WALL_MASK);
}
}
//墙壁
for (int i =1; i<=4; i++) {
auto str2 =__String::createWithFormat("wall_%d",i);
auto wall = node->getChildByName<Sprite*>(str2->getCString());
if (wall->getTag() == 25) {
auto body2 = PhysicsBody::createBox(Size(wall->getContentSize().width,wall->getContentSize().height));//den res fri
body2->setDynamic(false);
body2->getShape(0)->setFriction(0);
body2->getShape(0)->setRestitution(1);
wall->setPhysicsBody(body2);
wall->getPhysicsBody()->setContactTestBitmask(WALL_MASK);
}
}
//石头
for (int i =1; i<= 2; i++) {
auto str3 =__String::createWithFormat("stone_%d",i);
auto stone = node->getChildByName<Sprite*>(str3->getCString());
if (stone->getTag() == 45) {
// auto body2 = PhysicsBody::createBox(Size(stone->getContentSize().width,stone->getContentSize().height));//den res fri
//
auto body3 = PhysicsBody::createCircle(stone->getContentSize().width/2);
body3->setDynamic(false);
body3->getShape(0)->setFriction(0);
body3->getShape(0)->setRestitution(1.5);//弹力
stone->setPhysicsBody(body3);
stone->getPhysicsBody()->setContactTestBitmask(WALL_MASK);
}
}
}
开发者ID:baokuanze,项目名称:-,代码行数:59,代码来源:GameLayer.cpp
示例3: nextPosY
void PassGateComponent::onEnter()
{
Component::onEnter();
float centerPosition = nextPosY();
_mainNode = Node::create();
_mainNode->setPosition(Point(_visibleSize.width / 2, centerPosition));
this->getOwner()->addChild(_mainNode, 1);
// center point in the gate for the score updating (check the collision)
Node* gateCenterNode = Node::create();
auto gateCenterBody = PhysicsBody::createBox(Size(0, GATE_HEIGHT));
gateCenterBody->setCollisionBitmask(PASSGATE_CENTER_ID);
gateCenterBody->setDynamic(false);
gateCenterBody->setContactTestBitmask(true);
_mainNode->setPhysicsBody(gateCenterBody);
// area inside the gate
Node* gateNode = Node::create();
auto gateBody = PhysicsBody::createEdgeBox(Size(GATE_WIDTH, GATE_HEIGHT));
gateBody->setCollisionBitmask(PASSGATE_AREA_ID);
gateBody->setDynamic(false);
gateBody->setContactTestBitmask(true);
gateNode->setPhysicsBody(gateBody);
_mainNode->addChild(gateNode);
// height of top 'wall'
float height1 = _visibleSize.height - SCORE_LAYOUT_BORDER_SIZE * 2 - SCORE_TEXT_SIZE-GATE_HEIGHT;
// draw graphics of the top 'wall'
Sprite* topNode = Sprite::create("wall2.png", Rect(Vec2(0, centerPosition), Size(GATE_WIDTH, height1)));
topNode->setPosition(Point(0, topNode->getBoundingBox().getMaxY()+GATE_HEIGHT/2));
auto topBody = PhysicsBody::createEdgeBox(topNode->getContentSize());
topBody->setCollisionBitmask(OBSTACLE_ID);
topBody->setDynamic(false);
topBody->setContactTestBitmask(true);
topNode->setPhysicsBody(topBody);
_mainNode->addChild(topNode);
// draw graphics of the bottom 'wall'
Sprite* bottomNode = Sprite::create("wall2.png", Rect(Vec2(0, centerPosition), Size(GATE_WIDTH, height1)));
bottomNode->setPosition(Point(0, -(bottomNode->getBoundingBox().getMaxY() + GATE_HEIGHT / 2)));
auto bottomBody = PhysicsBody::createEdgeBox(bottomNode->getContentSize());
bottomBody->setCollisionBitmask(OBSTACLE_ID);
bottomBody->setDynamic(false);
bottomBody->setContactTestBitmask(true);
bottomNode->setPhysicsBody(bottomBody);
_mainNode->addChild(bottomNode);
//
auto collisionListener = EventListenerPhysicsContact::create();
collisionListener->onContactSeparate = CC_CALLBACK_1(PassGateComponent::onContactSeparate, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(collisionListener, gateNode);
}
开发者ID:kira333,项目名称:MyProjects,代码行数:55,代码来源:PassGateComponent.cpp
示例4: createPips
void GameLayer::createPips() {
for (int i = 0; i < 2; i++) {
auto pipeUp = Sprite::createWithSpriteFrame(
AtlasLoader::getInstance()->getSpriteFrameByName("pipe_up"));
auto pipeDown = Sprite::createWithSpriteFrame(
AtlasLoader::getInstance()->getSpriteFrameByName("pipe_down"));
pipeUp->setPosition(Vec2(0, -(PIPE_HEIGHT + PIPE_DISTANCE) / 2));
pipeDown->setPosition(Vec2(0, (PIPE_HEIGHT + PIPE_DISTANCE) / 2));
//创建物理属性
auto pipeUpBody = PhysicsBody::createBox(pipeUp->getContentSize(), PHYSICSSHAPE_MATERIAL_DEFAULT, Vec2::ZERO);
//设置为静态刚体
pipeUpBody->setDynamic(false);
pipeUpBody->getShape(0)->setRestitution(0.0f);
//设置刚体密度
pipeUpBody->getShape(0)->setDensity(1.0f);
pipeUpBody->setCategoryBitmask(OBST_MASK);
pipeUpBody->setCollisionBitmask(BIRD_MASK | OBST_MASK);
pipeUpBody->setContactTestBitmask(BIRD_MASK | OBST_MASK);
pipeUp->setPhysicsBody(pipeUpBody);
auto pipeDownBody = PhysicsBody::createBox(pipeDown->getContentSize(), PHYSICSSHAPE_MATERIAL_DEFAULT, Vec2::ZERO);
//设置为静态刚体
pipeDownBody->setDynamic(false);
pipeDownBody->getShape(0)->setRestitution(0.0f);
pipeDownBody->getShape(0)->setDensity(1.0f);
//设置碰撞掩码
pipeDownBody->setCategoryBitmask(OBST_MASK);
pipeDownBody->setCollisionBitmask(BIRD_MASK | OBST_MASK);
pipeDownBody->setContactTestBitmask(BIRD_MASK | OBST_MASK);
pipeDown->setPhysicsBody(pipeDownBody);
auto singlePipe = Node::create();
singlePipe->addChild(pipeUp);
singlePipe->addChild(pipeDown);
if (i == 0) {
singlePipe->setPosition(Vec2(SCREEN_WIDTH * 2 + PIPE_WIDHT / 2, 250));
} else {
singlePipe->setPosition(Vec2(SCREEN_WIDTH * 2.5f + PIPE_WIDHT, this->getRandomHeight()));
}
singlePipe->setTag(PIPE_NEW);
this->addChild(singlePipe);
this->pipes.pushBack(singlePipe);
}
}
开发者ID:ahjsrhj,项目名称:MyBird,代码行数:51,代码来源:GameLayer.cpp
示例5: setDeck
void KDeckDefStatic::Init(System::File::KTabFile2* fileReader)
{
char buf[1024];
fileReader->GetInteger("ID", 0, (int*)&m_Id);
fileReader->GetInteger("HeroID", 0, (int*)&m_heroID);
fileReader->GetInteger("HeroHp", 0, (int*)&m_heroHp);
fileReader->GetInteger("Res", 0, (int*)&m_res);
fileReader->GetInteger("Rnd", 0, (int*)&m_rnd);
fileReader->GetInteger("HeroStrong", 0, (int*)&m_heroStrong);
fileReader->GetInteger("ResLucky", 0, (int*)&m_resLucky);
fileReader->GetInteger("HeroLucky", 0, (int*)&m_heroLucky);
fileReader->GetInteger("Fate", 0, (int*)&m_fate);
fileReader->GetString("DECK", "", buf, 1023);
setDeck(buf);
fileReader->GetInteger("DrawNum", 0, (int*)&m_drawNum);
fileReader->GetString("HeroSkill", "", buf, 1023);
setHeroSkill(buf);
fileReader->GetString("Dynamic", "", buf, 1023);
setDynamic(buf);
}
开发者ID:joyfish,项目名称:zgc,代码行数:25,代码来源:KDeckDefStatic.cpp
示例6: Point
bool Player::init()
{
if (!Sprite::initWithFile("graphics/luk_sprite.png"))
{
return false;
}
//Point PBox[8]{Point(-2, -12), Point(-4, -10), Point(-4, -2), Point(-2, 0), Point(2, 0), Point(4, -2), Point(4, -10), Point(2, -12)};
Point PBox[4]{Point(-4, -12), Point(-4, 0), Point(4, 0), Point(4, -12)};
//auto body = PhysicsBody::createEdgePolygon(PBox, 4,PHYSICSBODY_MATERIAL_DEFAULT,0.5f);
auto body = PhysicsBody::createPolygon(PBox, 4);
body->setEnable(true);
body->setDynamic(true);
body->setGravityEnable(true);
body->setRotationEnable(false);
body->setVelocityLimit(30.0);
body->setCategoryBitmask(static_cast<int>(Stage::TileType::PLAYER));
//BLOCKSとの接触判定をON
//body->setCollisionBitmask(static_cast<int>(Stage::TileType::BLOCKS));
body->setCollisionBitmask(static_cast<int>(Stage::TileType::NONE));
body->setContactTestBitmask(static_cast<int>(Stage::TileType::BLOCKS));
//body->setContactTestBitmask(INT_MAX);
this->setPhysicsBody(body);
this->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
this->scheduleUpdate();
return true;
}
开发者ID:raa0121,项目名称:mirumirrormini,代码行数:33,代码来源:Player.cpp
示例7: Point
void GameLayer::createPips() {
// Create the pips
for (int i = 0; i < PIP_COUNT; i++) {
Size visibleSize = Director::getInstance()->getVisibleSize();
Sprite *pipUp = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("pipe_up"));
Sprite *pipDown = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("pipe_down"));
Node *singlePip = Node::create();
// bind to pair
pipDown->setPosition(0, PIP_HEIGHT + PIP_DISTANCE);
singlePip->addChild(pipDown, 0, DOWN_PIP);
singlePip->addChild(pipUp, 0, UP_PIP);
singlePip->setPosition(visibleSize.width + i*PIP_INTERVAL + WAIT_DISTANCE, this->getRandomHeight());
auto body = PhysicsBody::create();
auto shapeBoxDown = PhysicsShapeBox::create(pipDown->getContentSize(),PHYSICSSHAPE_MATERIAL_DEFAULT, Point(0, PIP_HEIGHT + PIP_DISTANCE));
body->addShape(shapeBoxDown);
body->addShape(PhysicsShapeBox::create(pipUp->getContentSize()));
body->setDynamic(false);
//ÉèÖÃÅöײ
body->setCategoryBitmask(ColliderTypePip);
body->setCollisionBitmask(ColliderTypeBird);
body->setContactTestBitmask(ColliderTypeBird);
singlePip->setPhysicsBody(body);
singlePip->setTag(PIP_NEW);
this->addChild(singlePip);
this->pips.push_back(singlePip);
}
}
开发者ID:whumr,项目名称:bird,代码行数:31,代码来源:GameLayer.cpp
示例8:
void Coin3::spawnCoin3(cocos2d::Layer * layer)
{
auto coin=Sprite::create("Candy (3).png");
const float SCALE_TO_DEVICE = Director::getInstance()->getVisibleSize().width / DES_RES_X;
coin->setScale(SCALE_TO_DEVICE * 2);
//coin->setScale(2, 2);
auto ran=CCRANDOM_0_1();
auto posi_x=origin.x+coin->getContentSize().width* SCALE_TO_DEVICE/2+ran*(visibleSize.width-coin->getContentSize().width* SCALE_TO_DEVICE);
auto posi_y=origin.y+visibleSize.height;
auto body=PhysicsBody::createBox(coin->getContentSize()*2* SCALE_TO_DEVICE);
body->setDynamic(false);
body->setCollisionBitmask(COIN3_COLLISION_BITMASK);
body->setContactTestBitmask(COIN3_CONTACT_BITMASK);
coin->setPhysicsBody(body);
coin->setPosition(Point(posi_x,posi_y));
layer->addChild(coin,7);
auto move_dis=visibleSize.height+coin->getContentSize().height* SCALE_TO_DEVICE+50;
auto move_duration=COIN3_SPEED*move_dis;
auto coin_move=MoveBy::create(move_duration,Point(0,-move_dis));
coin->runAction(Sequence::create(coin_move,RemoveSelf::create(true),nullptr));
}
开发者ID:Noctiz-Jin,项目名称:Halloween-Candy-Rush-Night,代码行数:25,代码来源:Coin3.cpp
示例9: PhysicsMaterial
Sprite* Stage::addPhysicsBody(cocos2d::TMXLayer *layer, cocos2d::Vec2 &coordinate)
{
// タイル1枚の大きさを取り出す
auto tileSize = _tiledMap->getTileSize();
// タイルのスプライトを取り出す
auto sprite = layer->getTileAt(coordinate);
if (sprite) {
// タイルのIDを取り出す
auto gid = layer->getTileGIDAt(coordinate);
// タイルのプロパティをmapで取り出す
auto property = _tiledMap->getPropertiesForGID(gid);
if (property.isNull() || property.getType() != Value::Type::MAP) {
return nullptr;
}
auto properties = property.asValueMap();
// プロパティの中からcategoryの値をintとして取り出す
auto category = properties.at("category").asInt();
auto material = PhysicsMaterial();
material.friction = 0;
material.restitution = 0.1;
// 剛体を設置する
auto physicsBody = PhysicsBody::createBox(sprite->getContentSize(), material);
// 剛体を固定する
physicsBody->setDynamic(false);
// 剛体にカテゴリをセットする
physicsBody->setCategoryBitmask(category);
// 剛体と接触判定を取るカテゴリを指定する
physicsBody->setContactTestBitmask(static_cast<int>(TileType::PLAYER));
// 剛体と衝突を取るカテゴリを指定する
physicsBody->setCollisionBitmask(static_cast<int>(TileType::PLAYER));
// アニメーションを付ける
// プロパティにanimationの値があったら
if (!properties["animation"].isNull()) {
auto animationSprite = properties["animation"].asString();
auto animationCount = properties["animationCount"].asInt();
sprite->removeFromParent();
this->addChild(sprite);
Vector<SpriteFrame *> frames;
auto scale = 0.5;
for (int i = 0; i < animationCount; ++i) {
auto frame = SpriteFrame::create(animationSprite, Rect(tileSize.width * i * scale, 0, tileSize.width * scale, tileSize.height * scale));
frames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(frames);
animation->setDelayPerUnit(0.15);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
}
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
sprite->setPhysicsBody(physicsBody);
return sprite;
}
return nullptr;
}
开发者ID:ZenexHentai,项目名称:KawazJet,代码行数:60,代码来源:Stage.cpp
示例10: Point
void GameScreen::spawnAsteroid(float dt)
{
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
int asteroidIndex = (arc4random() % 3) + 1;
__String* asteroidString = __String::createWithFormat("GameScreen/Asteroid_%i.png", asteroidIndex);
Sprite* tempAsteroid = Sprite::create(asteroidString->getCString());
int xRandomPosition = (arc4random() % (int)(visibleSize.width - (tempAsteroid->getContentSize().width / 2))) + (tempAsteroid->getContentSize().width / 2);
tempAsteroid->setPosition(
Point(xRandomPosition + origin.x,
-tempAsteroid->getContentSize().height + origin.y));
asteroids.push_back(tempAsteroid);
auto body = PhysicsBody::createCircle(asteroids[asteroids.size() - 1]->getContentSize().width / 2);
body->setContactTestBitmask(true);
body->setDynamic(true);
asteroids[asteroids.size() - 1]->setPhysicsBody(body);
this->addChild(asteroids[asteroids.size() - 1], -1);
}
开发者ID:duongbadu,项目名称:MyGame,代码行数:25,代码来源:GameScene.cpp
示例11: fireball_an
void FireBall::spawnFireBall(cocos2d::Layer * layer)
{
auto FireBall=cocos2d::Sprite::create("FireBall.png");
auto ran=CCRANDOM_0_1();
auto posi_x=ran*visibleSize.width+origin.x;
auto posi_y=origin.y+visibleSize.height+FireBall->getContentSize().height;
Vector<SpriteFrame*> fireball_an(4);
fireball_an.pushBack(SpriteFrame::create("FireBall.png", Rect(0,0,58,96)));
fireball_an.pushBack(SpriteFrame::create("FireBall_2.png", Rect(0,0,58,96)));
fireball_an.pushBack(SpriteFrame::create("FireBall.png", Rect(0,0,58,96)));
fireball_an.pushBack(SpriteFrame::create("FireBall_3.png", Rect(0,0,58,96)));
auto ann=Animation::createWithSpriteFrames(fireball_an,0.1f);
auto anim_ll=Animate::create(ann);
auto anim_l=RepeatForever::create(anim_ll);
FireBall->runAction(anim_l);
auto FireBall_body=cocos2d::PhysicsBody::createBox(FireBall->getContentSize());
FireBall_body->setDynamic(false);
FireBall_body->setCollisionBitmask(FIREBALL_COLLISION_BITMASK);
FireBall_body->setContactTestBitmask(FIREBALL_CONTACT_BITMASK);
FireBall->setPhysicsBody(FireBall_body);
FireBall->setPosition(Point(posi_x,posi_y));
layer->addChild(FireBall,102);
auto move_dis=visibleSize.height+FireBall->getContentSize().height+130;
auto move_duration=FIREBALL_SPEED*move_dis;
auto FireBall_move=cocos2d::MoveBy::create(move_duration,Point(0,-move_dis));
FireBall->runAction(Sequence::create(FireBall_move,RemoveSelf::create(true),nullptr));
}
开发者ID:Noctiz-Jin,项目名称:NocFall-iOS,代码行数:33,代码来源:FireBall.cpp
示例12: getContentSize
void Paddle::createPhysicsBody() {
auto bodySize = getContentSize();
auto width2 = bodySize.width / 2;
auto width4 = width2 / 2;
auto width8 = width4 / 2;
auto height2 = bodySize.height / 2;
auto height4 = height2 / 2;
auto height8 = height4 / 2;
// Create this oval shape so that, when the ball bounces closer to the edges,
// its direction changes slightly.
std::array<Point, 12> bodyPoints = {
Point(width4, height2),
Point(width2 - width8, height2 - height8),
Point(width2, height8),
Point(width2, -height8),
Point(width2 - width8, -height2 + height8),
Point(width4, -height2),
Point(-width4, -height2),
Point(-width2 + width8, -height2 + height8),
Point(-width2, -height8),
Point(-width2, height8),
Point(-width2 + width8, height2 - height8),
Point(-width4, height2)
};
auto body = PhysicsBody::createPolygon(bodyPoints.data(), bodyPoints.size(), MATERIAL);
body->setDynamic(false);
body->setContactTestBitmask(BITMASK_CONTACT_TEST);
setPhysicsBody(body);
}
开发者ID:changbiao,项目名称:cocos2d-x-pong-cpp,代码行数:33,代码来源:Paddle.cpp
示例13: Balloon
Balloon* Balloon::createWithForce(Point* pos, Point* force)
{
Balloon* b = new Balloon();
if (b && b->initWithFile("balloon.png"))
{
// Set auto release.
b->autorelease();
// Set Scale
b->setScale(0.15f);
// Set Position
b->setPosition(*pos);
// CHANGE TO A DEFINED NUMBER AFTER
//this->setTag(0);
auto body = PhysicsBody::createCircle(b->getBoundingBox().size.width/2.5f);
body->setMass(1);
body->setDynamic(true);
body->setContactTestBitmask(2);
body->setCategoryBitmask(0x01); //0001
b->setPhysicsBody(body);
// give forces
b->getPhysicsBody()->applyImpulse(*force);
b->schedule(schedule_selector(Balloon::update));
return b;
}
CC_SAFE_DELETE(b);
return NULL;
}
开发者ID:ricky-flyguy,项目名称:RMZ_2014,代码行数:34,代码来源:Balloon.cpp
示例14: Rect
bool Player::init()
{
if (!Sprite::initWithFile("graphics/luk_sprite.png"))
{
return false;
}
this->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
cocos2d::Point PBox[8]{cocos2d::Point(-2, -12), cocos2d::Point(-4, -10), cocos2d::Point(-4, -2), cocos2d::Point(-2, 0), cocos2d::Point(2, 0), cocos2d::Point(4, -2), cocos2d::Point(4, -10), cocos2d::Point(2, -12)};
playerRect = Rect();
auto body = PhysicsBody::createPolygon(PBox, 8);
body->setEnable(true);
body->setDynamic(true);
body->setGravityEnable(true);
body->setRotationEnable(false);
body->setVelocityLimit(30.0);
body->setCategoryBitmask(static_cast<int>(Stage::TileType::PLAYER));
//BLOCKSとの接触判定をON
body->setCollisionBitmask(static_cast<int>(Stage::TileType::EMPTY));
body->setContactTestBitmask(static_cast<int>(Stage::TileType::BLOCKS));
//body->setContactTestBitmask(INT_MAX);
this->setPhysicsBody(body);
this->scheduleUpdate();
return true;
}
开发者ID:Tetu-fs,项目名称:mirumirrormini,代码行数:28,代码来源:Player.cpp
示例15: PhysicsMaterial
void Devil::InitSprite()
{
auto body = PhysicsBody::createBox(this->getContentSize(), PhysicsMaterial(100, 1, 1));
body->setDynamic(true);
body->setGravityEnable(false);
body->setRotationEnable(false);
body->setCollisionBitmask(MONSTER_BODY_COLLISION_BITMASK);
body->setContactTestBitmask(true);
this->setPhysicsBody(body);
this->setUserData(this);
hpBgSpr = Sprite::create("Monster/hpBg.png");
this->addChild(hpBgSpr, ZINDEX_MONSTER_HP);
hpCurrentSpr = Sprite::create("Monster/hpCurrent.png");
this->addChild(hpCurrentSpr, ZINDEX_MONSTER_HP);
auto origin = Director::getInstance()->getVisibleOrigin();
hpBgSpr->setPosition(Vec2(this->getContentSize().width / 2, this->getPosition().y + this->getContentSize().height + hpBgSpr->getContentSize().height / 2));
hpCurrentSpr->setPosition(hpBgSpr->getPosition());
hpBgSpr->setOpacity(0);
hpCurrentSpr->setOpacity(0);
fury = CSLoader::createNode("Effect/Rage/Rage.csb");
fury->setPosition(this->getContentSize().width * 0.5f, this->getContentSize().height * 0.5f);
this->addChild(fury);
fury->setVisible(false);
auto visibleSize = Director::getInstance()->getVisibleSize();
d = Dragon::create(layer);
d->setPosition(visibleSize.width*0.7f, visibleSize.height*0.7f);
layer->addChild(d, ZINDEX_MONSTER_SPRITE);
d->scheduleUpdate();
}
开发者ID:ilhaeYe,项目名称:MB,代码行数:33,代码来源:Devil.cpp
示例16: spawn_hanhtinh
void Hanhtinh::spawn_hanhtinh( float dt )
{
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
int hanhtinh_index = (rand() % 2) + 1;
__String* hanhtinh_String = __String::createWithFormat("GameScreen/Asteroid_%i.png", hanhtinh_index);
Sprite* tempHanhtinh = Sprite::create(hanhtinh_String->getCString());
int yRandomPosition = (rand() % (int)(visibleSize.height - (tempHanhtinh->getContentSize().height / 2))) +
(tempHanhtinh->getContentSize().height / 2);
//int xRandomPosition = (rand() % (int)(visibleSize.width/2));
tempHanhtinh->setPosition(Point( visibleSize.width, yRandomPosition ));
hanhtinh.push_back(tempHanhtinh);
auto hanhtinh_body = PhysicsBody::createCircle( hanhtinh[hanhtinh.size() -1 ]->getContentSize().width /2 );
hanhtinh_body->setContactTestBitmask(true);
hanhtinh_body->setDynamic(true);
hanhtinh[hanhtinh.size() -1 ]->setPhysicsBody(hanhtinh_body);
hanhtinh[hanhtinh.size() -1]->setTag(TAG_HANHTINH);
this->addChild(hanhtinh[hanhtinh.size() - 1], -1);
}
开发者ID:kenhaui,项目名称:HelloGame,代码行数:25,代码来源:Hanhtinh.cpp
示例17: createBall
void BreakoutMainScene::createBall()
{
// Create Ball
cocos2d::log("Create Ball");
// Tao qua bong va thiet lap khung vat ly cho no
ball = Sprite::create("breakout_img/breakout_ball.png");
ball->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
ball->setPosition(Vec2(WINSIZE.width/2 , WINSIZE.height/2 + 50));
auto ballBody = PhysicsBody::createCircle(ball->getContentSize().width/2 , PHYSICSBODY_MATERIAL_DEFAULT);
ballBody->getShape(0)->setDensity(1.0f); // trong luc
ballBody->getShape(0)->setFriction(0.0f);
ballBody->getShape(0)->setRestitution(1.0f);
ballBody->setDynamic(true);
ballBody->setContactTestBitmask(0x00000001);
ballBody->setGravityEnable(false); // Khong set gia toc
// Tao 1 luc tac dong
Vect force = Vect(900000.0f, -900000.0f);
ballBody->applyImpulse(force);
ball->setPhysicsBody(ballBody);
ball->setTag(Tag::T_Ball);
this->addChild(ball);
}
开发者ID:vienbk91,项目名称:parkour,代码行数:28,代码来源:BreakoutMainScene.cpp
示例18: CCLOG
void Pipe::SpawnPipe(Layer* layer)
{
CCLOG("SPAWN PIPE");
Vec2 centerScreen = ((Vec2)visibleSize / 2.0f) + origin;
auto topPipe = Sprite::create("Pipe.png");
auto bottomPipe = Sprite::create("Pipe.png");
auto topPipeBody = PhysicsBody::createBox(topPipe->getContentSize());
auto bottomPipeBody = PhysicsBody::createBox(bottomPipe->getContentSize());
auto random = CCRANDOM_0_1();
if (random < LOWER_SCREEN_PIPE_THRESHOLD)
{
random = LOWER_SCREEN_PIPE_THRESHOLD;
}
else if ( random > UPPER_SCREEN_PIPE_THRESHOLD)
{
random = UPPER_SCREEN_PIPE_THRESHOLD;
}
auto topPipePosition = (random * visibleSize.height) + (topPipe->getContentSize().height / 2.0f);
topPipeBody->setDynamic(false);
bottomPipeBody->setDynamic(false);
topPipeBody->setCollisionBitmask(OBSTACLE_COLLISION_BITMASK);
bottomPipeBody->setCollisionBitmask(OBSTACLE_COLLISION_BITMASK);
topPipeBody->setContactTestBitmask(true);
bottomPipeBody->setContactTestBitmask(true);
topPipe->setPhysicsBody(topPipeBody);
bottomPipe->setPhysicsBody(bottomPipeBody);
topPipe->setPosition(Point(visibleSize.width + topPipe->getContentSize().width + origin.x, topPipePosition));
bottomPipe->setPosition(Point(topPipe->getPositionX(), topPipePosition - (Sprite::create("Ball.png")->getContentSize().height * PIPE_GAP) - topPipe->getContentSize().height));
layer->addChild(topPipe);
layer->addChild(bottomPipe);
auto topPipeAction = MoveBy::create(PIPE_MOVEMENT_SPEED * visibleSize.width, Point(-visibleSize.width * 1.5, 0));
auto bottomPipeAction = MoveBy::create(PIPE_MOVEMENT_SPEED * visibleSize.width, Point(-visibleSize.width * 1.5, 0));
topPipe->runAction(topPipeAction);
bottomPipe->runAction(bottomPipeAction);
}
开发者ID:NinePinNoTap,项目名称:FlappyBirdClone,代码行数:47,代码来源:Pipe.cpp
示例19: setSprite
void Block::init(cocos2d::Sprite *sprite, const std::string& name) {
GameObject::init(name);
setSprite(sprite);
setName(name);
auto world = Physics::getWorld2D();
auto physicsBody = world->addBody(sprite, name, "block");
physicsBody->setDynamic(false);
}
开发者ID:nshermione,项目名称:pingpongcocos2dx,代码行数:8,代码来源:Block.cpp
示例20: Point
bool Bullet::init (int tag)
{
// if (!Sprite::initWithFile("faceball.png")){
if (!Sprite::initWithFile("ball.png")){
return false;
}
m_tag = tag;
this->setColor(_tagColor[tag]);
// 大きさをランダムにとりあえず
bulletSize = _bulSize[tag];
// this->setContentSize(cocos2d::Size (bulletSize * 20, bulletSize * 20));
// もともと設定されてたもの
// なんか、物理エンジンがおかしくなるような気がする
// これを消すと落ち着く
this->setScale(0.13f * bulletSize);
//this->setScale(0.043f * bulletSize);
// 密度、反発、摩擦
// まるいやつ。回転がわかりズラい
// auto pBall = PhysicsBody::createCircle(bulletSize,
// PhysicsMaterial(10.0f, 0.6f, 0.3f));
// しかくいやつ。これは四角すぎる
// auto pBall = PhysicsBody::createBox(cocos2d::Size(bulletSize, bulletSize), PhysicsMaterial(1.0f, 0.6f, 0.3f));
Point spritePoints[12] =
{
Point(-1, 0.333) *= bulletSize, Point(-0.666, 0.5) *= bulletSize, Point(-0.333, 0.666) *= bulletSize,
Point(0.333, 0.666) *= bulletSize, Point(0.666, 0.5) *= bulletSize, Point(1, 0.333) *= bulletSize,
Point(1, -0.333) *= bulletSize, Point(0.666, -0.5) *= bulletSize, Point(0.333, -0.666) *= bulletSize,
Point(-0.333, -0.666) *= bulletSize, Point(-0.666, -0.5) *= bulletSize, Point(-1, -0.333) *= bulletSize
};
// for (Point target : spritePoints) {
// target *= bulletSize;
// }
// 密度、反発、摩擦
auto pBall = PhysicsBody::createPolygon(spritePoints, 12, PhysicsMaterial(1.0f, 0.0f, 1.0f));
// auto pBall = PhysicsBody::createPolygon(spritePoints, 12, PhysicsMaterial(1.0f, 0.6f, 0.3f));
pBall->setDynamic(true);
pBall->setRotationEnable(true);
// 回転率?なのか?これを無限にすると回転しない
// pBall->setMoment(PHYSICS_INFINITY);
// pBall->setMoment(bulletSize);
pBall->setGravityEnable(true);
//log("%f",pBall->getMass());
// pBall->setMass(1.0);
pBall->setVelocityLimit(800);
this->setPhysicsBody(pBall);
return true;
}
开发者ID:kimujinyogi,项目名称:Pakuri,代码行数:57,代码来源:Bullet.cpp
注:本文中的setDynamic函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论