本文整理汇总了C++中setContactTestBitmask函数的典型用法代码示例。如果您正苦于以下问题:C++ setContactTestBitmask函数的具体用法?C++ setContactTestBitmask怎么用?C++ setContactTestBitmask使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setContactTestBitmask函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
bool Bullet::init(int iType)
{
if (!Sprite::init())
{
return false;
}
if (iType == BulletType::Bullet_Player_main)
{
this->initWithFile("bullet/pet_bullet.png");
this->setTag(ObjectType::TYPE_PLAYER_BULLET);
auto body = PhysicsBody::createCircle(5.0f);
body->setCategoryBitmask(Gategorybitmask::GATEGORYBITMASK_PLAYER);
body->setContactTestBitmask(0xFFFFFFFF);
body->setCollisionBitmask(Collisionbitmask::COLLISIONBITMASK_PLAYER_BULLET);
this->setPhysicsBody(body);
body->setVelocity(Vec2(0, 500));
}
else if (iType == BulletType::Bullet_Player_second)
{
this->initWithFile("bullet/assisent1_01.png");
this->setTag(ObjectType::TYPE_PLAYER_BULLET);
auto body = PhysicsBody::createCircle(5.0f);
body->setCategoryBitmask(Gategorybitmask::GATEGORYBITMASK_PLAYER);
body->setContactTestBitmask(0xFFFFFFFF);
body->setCollisionBitmask(Collisionbitmask::COLLISIONBITMASK_PLAYER_BULLET);
this->setPhysicsBody(body);
body->setVelocity(Vec2(0, 1000));
}
return true;
}
示例2: srand
// on "init" you need to initialize your instance
bool GameScene::init()
{
//////////////////////////////
// 1. super init first
if (!Layer::init())
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
//set background
auto backgroundSprite = Sprite::create("Background.jpg");
backgroundSprite->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
//set food
food = Sprite::create("Food.png");
srand(time(NULL));
auto random = rand() % 370 + 30;
auto random2 = rand() % 270 + 30;
food->setPosition(Point(random, random2));
auto foodBody = PhysicsBody::createCircle(food->getContentSize().width / 2);
foodBody->setCollisionBitmask(FOOD_COLLISION_BITMASK);
foodBody->setContactTestBitmask(true);
food->setPhysicsBody(foodBody);
//set snake particle
snake = Sprite::create("snake.png");
snake->setPosition(this->getBoundingBox().getMidX(), this->getBoundingBox().getMidY());
auto snakeBody = PhysicsBody::createCircle(snake->getContentSize().width / 2);
snakeBody->setCollisionBitmask(SNAKE_COLLISION_BITMASK);
snakeBody->setContactTestBitmask(true);
snake->setPhysicsBody(snakeBody);
snakeParts.push_back(snake);
snakeParts.front()->setPosition(100, 100);
selectSched = schedule_selector(GameScene::update);
//create the sprites
this->addChild(backgroundSprite, 0);
this->addChild(food, 1);
this->addChild(snakeParts.front(), 2);
auto eventListener = EventListenerKeyboard::create();
eventListener->onKeyPressed = CC_CALLBACK_2(GameScene::updateDirection, this);
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(eventListener, this);
auto contactListener = EventListenerPhysicsContact::create();
contactListener->onContactBegin = CC_CALLBACK_1(GameScene::onContactBegin, this);
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(contactListener, this);
this->schedule(selectSched, 0.1);
return true;
}
示例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);
}
示例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);
}
}
示例5: onTouchBegan
bool HelloWorld::onTouchBegan(Touch* pTouch, Event* pEvent)
{
Size visibleSize = Director::getInstance()->getVisibleSize();
Point touchLocation = pTouch->getLocationInView();
touchLocation = Director::getInstance()->convertToGL(touchLocation);
Sprite* projectileExmaple = Sprite::create("projectile-hd.png");
j+=1;
auto OneBody = PhysicsBody::createBox(projectileExmaple->getContentSize());
OneBody->applyImpulse(Vect(100,500));
OneBody->setContactTestBitmask(0x04);
projectileExmaple->setPhysicsBody(OneBody);
projectileExmaple->setPosition(visibleSize.width/8,visibleSize.height/2);
projectile.push_back(projectileExmaple);
this->addChild(projectile.back(),j);
Point offset = ccpSub(touchLocation, _player->getPosition());
float ratio = offset.y/offset.x;
int targetX = _player->getContentSize().width/2 + visibleSize.width;
int targetY = (targetX*ratio) + _player->getPosition().y;
Vec2 targetPosition = Vec2(targetX,targetY);
MoveTo* Move = MoveTo::create(2, targetPosition);
projectile.back()->runAction(Move);
return true;
}
示例6: MayBay
MayBay * MayBay::Create(){
MayBay * obj = new MayBay();
auto SpFrameCache = SpriteFrameCache::getInstance();
SpFrameCache->addSpriteFramesWithFile("plane/plane.plist");
if(!obj->initWithSpriteFrame(SpFrameCache->getSpriteFrameByName("planeRed1.png"))){
CCLOG("Cant not create maybay");
}
else{
Vector<SpriteFrame*> vecFrm(3);
char str[50]={0};
for(int i=1; i<=3 ;i++){
sprintf(str,"planeRed%d.png",i);
auto spFrm = SpFrameCache->getSpriteFrameByName(str);
vecFrm.pushBack(spFrm);
}
auto animation = Animation::createWithSpriteFrames(vecFrm,0.1f);
auto ani= Animate::create(animation);
obj->runAction(RepeatForever::create(ani));
}
auto physic = PhysicsBody::createBox(Size(Vec2(obj->getContentSize().width-10,obj->getContentSize().height-10)),PhysicsMaterial(1,0,1));
physic->setCollisionBitmask(0x001);
physic->setCategoryBitmask(0x001);
physic->setContactTestBitmask(true);
physic->setTag(10);
obj->setPhysicsBody(physic);
obj->getPhysicsBody()->setGravityEnable(false);
obj->setFly();
return obj;
}
示例7: 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);
}
示例8: Movements
void PlayerComponent::onEnter()
{
Component::onEnter();
_movements = new Movements(_startPosition);
// draw player graphic
_player = Sprite::create("circle.png");
_player->setPosition(_movements->getPoint());
_player->setScale(.5f);
this->getOwner()->addChild(_player);
// set the draw nodes
_drawPointNode = DrawNode::create();
_player->addChild(_drawPointNode, -1);
_drawLineNode = DrawNode::create();
_player->addChild(_drawLineNode, -2);
// set collision mask
auto body = PhysicsBody::createCircle(_player->getContentSize().height / 2);
body->setCollisionBitmask(PLAYER_ID);
body->setContactTestBitmask(true);
_player->setPhysicsBody(body);
//
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = CC_CALLBACK_2(PlayerComponent::onTouchBegan, this);
touchListener->onTouchEnded = CC_CALLBACK_2(PlayerComponent::onTouchEnded, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, _player);
auto collisionListener = EventListenerPhysicsContact::create();
collisionListener->onContactBegin = CC_CALLBACK_1(PlayerComponent::onContactBegin, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(collisionListener, _player);
}
示例9: 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);
}
}
示例10: CC_BREAK_IF
bool RoleSupplyDoubleGun::init() {
bool bRet = false;
do {
CC_BREAK_IF(!Sprite::initWithSpriteFrameName("ufo1.png"));
// set physical body
auto body = PhysicsBody::createBox(getContentSize());
body->setGroup(PHYSICAL_BODY_SUPPLY_GROUP);
body->setCategoryBitmask(PHYSICAL_BODY_SUPPLY_BITMASK_CATEGORY);
body->setContactTestBitmask(PHYSICAL_BODY_SUPPLY_BITMASK_CONTACT_TEST);
body->setCollisionBitmask(PHYSICAL_BODY_SUPPLY_BITMASK_COLLISION);
setPhysicsBody(body);
// set position
auto bigBoomSize = getContentSize();
auto winSize = Director::getInstance()->getWinSize();
int minX = bigBoomSize.width/2;
int maxX = winSize.width-bigBoomSize.width/2;
int rangeX = maxX-minX;
int actualX = (rand()%rangeX)+minX;
setPosition(Point(actualX, winSize.height+bigBoomSize.height/2));
// run action
auto move1 = MoveBy::create(0.5, Point(0, -150));
auto move2 = MoveBy::create(0.3, Point(0, 100));
auto move3 = MoveBy::create(1.0, Point(0, 0-winSize.height-bigBoomSize.height/2));
auto actionDone = RemoveSelf::create(true);
auto sequence = Sequence::create(move1, move2, move3, actionDone, nullptr);
runAction(sequence);
bRet = true;
} while (0);
return bRet;
}
示例11: 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);
}
示例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);
}
示例13: BossBullet
BossBullet * BossBullet::createBossBullet3()
{
BossBullet * bossBullet3 = new BossBullet();
if (bossBullet3 && bossBullet3->initWithFile("GameScreen/ss_boss1_attack3.png", Rect(0, 0, 36, 36)))
{
//Create and run animation
Vector<SpriteFrame*> animFrames(5);
char str[100] = { 0 };
for (int i = 0; i < 5; i++)
{
sprintf(str, "GameScreen/ss_boss1_attack3.png");
auto frame = SpriteFrame::create(str, Rect(36 * i, 0, 36, 36)); //we assume that the sprites' dimentions are 30x30 rectangles.
animFrames.pushBack(frame);
}
auto animation = CCAnimation::createWithSpriteFrames(animFrames, 0.15f, 100000);
auto animate = CCAnimate::create(animation);
//make body for collisions
cocos2d::Size size(36, 36);
auto bossBulletBody = PhysicsBody::createBox(size);
bossBulletBody->setCollisionBitmask(0x000006);
bossBulletBody->setContactTestBitmask(true);
bossBullet3->setPhysicsBody(bossBulletBody);
bossBulletBody->setTag(60);
bossBullet3->runAction(animate);
bossBullet3->initBullet();
bossBullet3->setTag(60);
return bossBullet3;
}
CC_SAFE_DELETE(bossBullet3);
return NULL;
}
示例14:
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));
}
示例15: PhysicsMaterial
Bird::Bird(cocos2d::Layer *layer){
visibleSize = Director::getInstance()->getVisibleSize();
origin = Director::getInstance()->getVisibleOrigin();
flappyBird = Sprite::create("Will.png");
flappyBird->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
willLocationX = flappyBird->getPositionX();
willLocationY = flappyBird->getPositionY();
auto flappyBody = PhysicsBody::createBox(Size(flappyBird->getContentSize().width, flappyBird->getContentSize().height), PhysicsMaterial(0, 1, 0));
flappyBody->setGravityEnable(false);
flappyBird->setPhysicsBody(flappyBody);
layer -> addChild(flappyBird, 100);
flappyBody->setCollisionBitmask(BIRD_COLLISION_BITMASK);
flappyBody->setContactTestBitmask(true);
flappyBody->setMass(1);
//isFalling = true;
flappyBird->getPhysicsBody()->setVelocityLimit(300);
}