本文整理汇总了C++中GameScene::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ GameScene::addChild方法的具体用法?C++ GameScene::addChild怎么用?C++ GameScene::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameScene
的用法示例。
在下文中一共展示了GameScene::addChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create
GameScene* GameScene::create(const int gameType)
{
GameScene* result = new GameScene();
if (result->init())
{
GameLayer* layer = new GameLayer(gameType);
layer->autorelease();
result->addChild(layer);
return result;
}
delete result;
return NULL;
}
示例2: update
void InputLayer::update(float delta) {
GameScene *game = GameScene::getSharedGameScene();
totalTime += delta;
if (fireButton->getIsActive() && totalTime > nextShotTime) {
nextShotTime = totalTime + 0.5f;
DogEntity* trendoc = game->getDog();
Point trendocPos = CCPointMake(trendoc->getPosition().x + trendoc->getContentSize().width * 0.5f, trendoc->getPosition().y);
float spread = (CCRANDOM_0_1() - 0.5f) * 0.5f;
Point velocity = CCPointMake(15, 0);
Bullet *bullet = Bullet::initWithBulletForDoc();
bullet->setTag(game->getDogBulletTag());
game->addDogBulletTag();
game->addChild(bullet);
bullet->shootBulletAt(trendocPos, velocity, "bullet.png");
}
if (!fireButton->getIsActive()) {
nextShotTime = 0;
}
DogEntity *trendoc = game->getDog();
Point velocity = ccpMult(joystick->getVelocity(), 200);
if (velocity.x != 0 && velocity.y != 0) {
float newX = trendoc->getPosition().x + velocity.x * delta;
float newY = trendoc->getPosition().y + velocity.y * delta;
float halfWidth = trendoc->getContentSize().width * 0.5f;
float halfHeight = trendoc->getContentSize().height * 0.5f;
Size screensize = Director::getInstance()->getVisibleSize();
if (newX < halfWidth) {
newX = halfWidth;
}else if (newX > (screensize.width - halfWidth)) {
newX = screensize.width - halfWidth;
}
if (newY < halfHeight) {
newY = halfHeight;
}else if (newY > (screensize.height - halfHeight)) {
newY = screensize.height - halfHeight;
}
trendoc->setPosition(newX, newY);
}
}
示例3:
Radar::Radar(cocos2d::Layer & pGS, Point position)
{
this->_pGs = &pGS;
this->radarBg1 = Sprite::create("radarBG1.png");
this->radarBg1->setPosition(position);
GameScene* gs = (GameScene*) _pGs;
gs->addChild(radarBg1);
//populate the vector with the size of the mapinfo
for ( int i = 0; i < (gs->getMapInfo()->GetTilesPerLine() * gs->getMapInfo()->GetTilesPerColumn()); i++ )
{
this->map.push_back(RadarMapNode::Nothing);
}
}
示例4: handleContact
//处理碰撞土块
void TileSprite::handleContact(MarioSprite * pMario)
{
//无效土块判断
if (m_eTileType == TSType_Invalid)
return;
Vec2 pos = getPosition();
bool bMarioTumble = (pMario->getMarioStatus() == MarioSt_LTumble || pMario->getMarioStatus() == MarioSt_RTumble); //是否翻跟头
m_bFinishHandleContact = false;
//播放碰撞音效
if (!bMarioTumble)
{
if (m_eTileType == TSType_Null && pMario->getMarioLevel() > 1)
playEffect(Effect_DestroyTile);
else
playEffect(Effect_JackSolid);
}
if (m_eTileType == TSType_Null) //空土块
{
if (pMario->getMarioLevel() > 1) //正常马里奥的碰撞
{
GameScene * gameScene = GameScene::getInstance();
Sprite * broken1 = Sprite::createWithSpriteFrameName("tile/broken_tile1.png");
broken1->setPosition(Vec2(pos.x - 10, pos.y + 10));
broken1->setCameraMask(2);
gameScene->addChild(broken1, 10);
Sprite * broken2 = Sprite::createWithSpriteFrameName("tile/broken_tile2.png");
broken2->setPosition(pos);
broken2->setCameraMask(2);
gameScene->addChild(broken2, 10);
Sprite * broken3 = Sprite::createWithSpriteFrameName("tile/broken_tile3.png");
broken3->setPosition(Vec2(pos.x + 10, pos.y - 20));
broken3->setCameraMask(2);
gameScene->addChild(broken3, 10);
broken1->runAction(Sequence::create(JumpTo::create(bMarioTumble ? 0.5f : 1.0f, Vec2(pos.x - 350, -50.0f), bMarioTumble ? 150 : 300.0f, 1),
CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, broken1)), nullptr));
broken2->runAction(Sequence::create(JumpTo::create(bMarioTumble ? 0.5f : 1.0f, Vec2(pos.x - 50.0f, -50.0f), bMarioTumble ? 150 : 300.0f, 1),
CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, broken2)), nullptr));
broken3->runAction(Sequence::create(JumpTo::create(bMarioTumble ? 0.5f : 1.0f, Vec2(pos.x + 390.0f, -50.0f), bMarioTumble ? 150 : 300.0f, 1),
CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, broken3)), nullptr));
this->removeFromParent();
}
else //缩小版马里奥的碰撞
{
//设置基础动作
ActionInterval * baseAction = Spawn::create(
MoveBy::create(0.1f, Vec2(0.0f, bMarioTumble ? -20.0f : 20.0f)),
CCScaleBy::create(0.1f, 1.3f),
nullptr);
this->runAction(Sequence::create(
baseAction, baseAction->reverse(),
CallFunc::create(CC_CALLBACK_0(TileSprite::finishHandleContact, this)),
nullptr));
}
}
else if (m_eTileType == TSType_Coin) //金币土块
{
if (m_nCoinCount <= 0)
{
setInvalid();
return;
}
//设置基础动作
ActionInterval * baseAction = Spawn::create(MoveBy::create(0.1f, Vec2(0.0f, bMarioTumble ? -20.0f : 20.0f)),
CCScaleBy::create(0.1f, 1.3f), nullptr);
//根据金币数目设置土块动作
if (m_nCoinCount == 1)
{
this->runAction(Sequence::create(
baseAction, baseAction->reverse(),
CallFunc::create(CC_CALLBACK_0(TileSprite::setInvalid, this)),
CallFunc::create(CC_CALLBACK_0(TileSprite::finishHandleContact, this)),
nullptr));
}
else if (m_nCoinCount > 1)
{
this->runAction(Sequence::create(
baseAction, baseAction->reverse(),
CallFunc::create(CC_CALLBACK_0(TileSprite::finishHandleContact, this)),
nullptr));
}
--m_nCoinCount;
//设置金币动作
Sprite * pCoin = Sprite::createWithSpriteFrameName("coin/coin1.png");
Size size = getContentSize();
pCoin->setPosition(Vec2(size.width / 2, size.height / 2));
pCoin->setCameraMask(2);
this->addChild(pCoin, -1);
//.........这里部分代码省略.........