本文整理汇总了C++中SpriteBatchNode::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ SpriteBatchNode::addChild方法的具体用法?C++ SpriteBatchNode::addChild怎么用?C++ SpriteBatchNode::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpriteBatchNode
的用法示例。
在下文中一共展示了SpriteBatchNode::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createRemovablePlats
void LevelTwo::createRemovablePlats()
{
std::shared_ptr<GameData> ptr = GameData::sharedGameData();
SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile);
for (int i = 0; i < 4; i++)
{
if (i == 0)
{
TowerBase * removablePlats = TowerBase::create(Vec2(200, 338), m_gameState, 5);
m_removablePlats.push_back(removablePlats);
spritebatch->addChild(removablePlats, -5);
}
else if (i == 1)
{
TowerBase * removablePlats = TowerBase::create(Vec2(245, 338), m_gameState, 5);
m_removablePlats.push_back(removablePlats);
spritebatch->addChild(removablePlats, -5);
}
else if (i == 2)
{
TowerBase * removablePlats = TowerBase::create(Vec2(200, -100), m_gameState, 6);
m_removablePlats.push_back(removablePlats);
spritebatch->addChild(removablePlats, -5);
}
else if (i == 3)
{
TowerBase * removablePlats = TowerBase::create(Vec2(245, -100), m_gameState, 6);
m_removablePlats.push_back(removablePlats);
spritebatch->addChild(removablePlats, -5);
}
}
this->addChild(spritebatch, 1, END_SPRITE_BATCH);
}
示例2: InitAnimation
//INITS
void GameScreen::InitAnimation()
{
SpriteBatchNode* spritebatch = SpriteBatchNode::create("Assets/Animation/Idle.png");
SpriteFrameCache* cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("Assets/Animation/Idle.plist");
_santaPaused = Sprite::createWithSpriteFrameName("Assets/Santa/idle_0001.png");
spritebatch->addChild(_santaPaused);
addChild(spritebatch);
_santaPaused->setPosition(Vec2(-_winSizeW*0.5f, _winSizeH*0.7f));
Vector<SpriteFrame*> animFrames;
char str[100] = { 0 };
for (int i = 1; i <= 12; i++)
{
sprintf(str, "Assets/Santa/idle_%04d.png", i);
SpriteFrame* frame = cache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
_santaPaused->runAction(RepeatForever::create(Animate::create(animation)));
}
示例3: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !LayerColor::initWithColor(Color4B(255,255,255,255)) )
{
return false;
}
Texture2D *texture = TextureCache::sharedTextureCache()->addImage("Icon.png");
SpriteBatchNode* batch = SpriteBatchNode::createWithTexture(texture, 800);
this->addChild(batch);
for (int i = 0; i < 800; ++i)
{
int index = (i % 50) * 8;
int rowIndex = (i / 50) * 8;
Sprite *temp = Sprite::createWithTexture(texture);
temp->setPosition(Vec2(index, rowIndex));
batch->addChild(temp);
}
return true;
}
示例4: createButton
void LevelTwo::createButton()
{
std::shared_ptr<GameData> ptr = GameData::sharedGameData();
SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile);
for (int i = 0; i < ptr->m_numButton; i++)
{
Button * button = Button::create(Vec2(ptr->m_ButtonsX[i], ptr->m_ButtonsY[i]), 2);
m_button.push_back(button);
spritebatch->addChild(button, -5);
}
for (int i = 0; i < ptr->m_numButton; i++)
{
Button * button = Button::create(Vec2(ptr->m_ButtonsX[i], ptr->m_ButtonsY[i]), 3);
m_button.push_back(button);
spritebatch->addChild(button, -5);
}
this->addChild(spritebatch, 1, END_SPRITE_BATCH);
}
示例5: createEndGame
void LevelTwo::createEndGame()
{
std::shared_ptr<GameData> ptr = GameData::sharedGameData();
SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile);
for (int i = 0; i < ptr->m_numEndGame; i++)
{
endGame * endGame = endGame::create(Vec2(ptr->m_endGameX[i], ptr->m_endGameY[i]), 1);
m_end.push_back(endGame);
spritebatch->addChild(endGame, -5);
}
this->addChild(spritebatch, 1, END_SPRITE_BATCH);
}
示例6: createTowerBases
void Tutorial::createTowerBases()//creates the taxis
{
std::shared_ptr<GameData> ptr = GameData::sharedGameData();
SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile);
for (int i = 24; i < ptr->m_numberOfTowerBases; i++)//loops thru the taxi for tutorial
{
TowerBase * base = TowerBase::create(Vec2(ptr->m_towerBaseX[i], ptr->m_towerBaseY[i]), m_gameState);
m_towerBases.push_back(base);
spritebatch->addChild(base, 1);
}
this->addChild(spritebatch, 1, TOWERS_SPRITE_BATCH);
}
示例7: createHiddenPlatforms
void LevelTwo::createHiddenPlatforms()
{
std::shared_ptr<GameData> ptr = GameData::sharedGameData();
SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile);
for (int i = 0; i < ptr->m_numberOfHiddenPlatforms; i++)
{
TowerBase * HiddenPlat = TowerBase::create(Vec2(380, 470), m_gameState, 4);
m_hiddenPlats.push_back(HiddenPlat);
spritebatch->addChild(HiddenPlat, -5);
}
this->addChild(spritebatch, 1, HIDDEN_SPRITE_BATCH);
}
示例8: createAmbulances
void Tutorial::createAmbulances()//creates the ambulances
{
std::shared_ptr<GameData> ptr = GameData::sharedGameData();
SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile);
for (int i = 22; i < ptr->m_numberOfAmbulance; i++)//loops thru the ambulances for tutorial
{
Ambulance * base = Ambulance::create(Vec2(ptr->m_ambulancePosX[i], ptr->m_ambulancePosY[i]), m_gameState);
m_ambulances.push_back(base);
spritebatch->addChild(base, 1);
}
this->addChild(spritebatch, 1, COINS_SPRITE_BATCH);
}
示例9: createTrucks
void Tutorial::createTrucks()//creates the trucks
{
std::shared_ptr<GameData> ptr = GameData::sharedGameData();
SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile);
for (int i = 0; i < 10; i++)//loops thru the trucks for tutorial
{
Truck * base = Truck::create(Vec2(ptr->m_truckPosX[i], ptr->m_truckPosY[i]), m_gameState);
m_trucks.push_back(base);
spritebatch->addChild(base, 1);
}
this->addChild(spritebatch, 1, COINS_SPRITE_BATCH);
}
示例10: createCoins
void Tutorial::createCoins()//creates the coins
{
std::shared_ptr<GameData> ptr = GameData::sharedGameData();
SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile);
for (int i = 92; i < 104; i++)//loops thru the coins for tutorial
{
Coin * base = Coin::create(Vec2(ptr->m_coinPosX[i], ptr->m_coinPosY[i]), m_gameState);
m_coins.push_back(base);
spritebatch->addChild(base, 1);
}
this->addChild(spritebatch, 4, COINS_SPRITE_BATCH);
}
示例11: createPlatforms
void LevelTwo::createPlatforms()
{
std::shared_ptr<GameData> ptr = GameData::sharedGameData();
SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile);
for (int i = 0; i < ptr->m_numberOfLevelTwoPlats; i++)
{
TowerBase * base = TowerBase::create(Vec2(ptr->m_levelTwoPlatformsX[i], ptr->m_levelTwoPlatformsY[i]), m_gameState, 3);
m_levelTwoPlat.push_back(base);
spritebatch->addChild(base, -5);
}
this->addChild(spritebatch, 1, LEVELTWO_SPRITE_BATCH);
}
示例12: createTraps
void LevelTwo::createTraps()
{
std::shared_ptr<GameData> ptr = GameData::sharedGameData();
SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile);
for (int i = 0; i < 1; i++)
{
TowerGun * traps = TowerGun::create(Vec2(ptr->m_trapX[i], ptr->m_trapY[i]), 2, 520, 240);
m_traps.push_back(traps);
spritebatch->addChild(traps, -5);
}
for (int i = 0; i < 1; i++)
{
TowerGun * traps = TowerGun::create(Vec2(ptr->m_trapX[i], ptr->m_trapY[i]), 2, 970, 240);
m_traps.push_back(traps);
spritebatch->addChild(traps, -5);
}
for (int i = 0; i < 1; i++)
{
TowerGun * traps = TowerGun::create(Vec2(ptr->m_trapX[i], ptr->m_trapY[i]), 2, 590, 115);
m_traps.push_back(traps);
spritebatch->addChild(traps, -5);
}
for (int i = 0; i < 1; i++)
{
TowerGun * traps = TowerGun::create(Vec2(ptr->m_trapX[i], ptr->m_trapY[i]), 2, 790, 115);
m_traps.push_back(traps);
spritebatch->addChild(traps, -5);
}
for (int i = 0; i < 1; i++)
{
TowerGun * traps = TowerGun::create(Vec2(ptr->m_trapX[i], ptr->m_trapY[i]), 2, 990, 115);
m_traps.push_back(traps);
spritebatch->addChild(traps, -5);
}
this->addChild(spritebatch, -1, TRAPS_SPRITE_BATCH);
}
示例13: addBird
void HelloWorld::addBird(cocos2d::Point p)
{
SpriteBatchNode *parent = SpriteBatchNode::create("bird_hero.png");
m_pSpriteTexture = parent->getTexture();//获取纹理贴图
//将精灵批处理节点添加到层
this->addChild(parent,0,kTagParentNode);
// Sprite *sprite = Sprite::createWithTexture(m_pSpriteTexture,Rect(32*idx, 32*idy, 32, 32));
bird = Sprite::createWithTexture(m_pSpriteTexture);
parent->addChild(bird);
Size birdSize = m_pSpriteTexture->getContentSize();
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
bodyDef.userData = bird;
b2Body *body = world->CreateBody(&bodyDef);
//定义盒子形状
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(birdSize.width/2/PTM_RATIO, birdSize.height/2/PTM_RATIO);
b2FixtureDef fixtureDef;
// fixtureDef.filter.groupIndex = 0;
// fixtureDef.filter.maskBits = 0x0002;//掩码
// fixtureDef.filter.categoryBits = 0x0003;//设置分类码
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.f;//密度
fixtureDef.friction = 0.3f;
fixtureDef.restitution = 0.f;//弹性系数
body->CreateFixture(&fixtureDef);//用刚体创建夹具
//事件监听
auto listener1 = EventListenerTouchOneByOne::create();
listener1->setSwallowTouches(true);
listener1->onTouchBegan =[=](Touch *touch,Event *event)
{
//设置线性速度
body->SetLinearVelocity(b2Vec2(0, 7));
return true;
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);
}
示例14: animFrames
void gameLevel2::shipExplosions(Vec2 vec,bool scale) {
SpriteBatchNode* spritebatch = SpriteBatchNode::create("animations/explosion.png");
SpriteFrameCache* cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/explosion.plist");
auto explosion = Sprite::createWithSpriteFrameName("explosion_01.png");
explosion->setPosition(vec);
if (scale) explosion->setScale(0.5);
spritebatch->addChild(explosion);
this->addChild(spritebatch);
Vector<SpriteFrame*> animFrames(48);
char str[100] = { 0 };
for (int i = 1; i < 49; i++)
{
sprintf(str, "explosion_%02d.png", i);
SpriteFrame* frame = cache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.02);
explosion->runAction(Sequence::create(Animate::create(animation),RemoveSelf::create(),NULL));
}
示例15: init
bool TitleScreen::init()
{
//////////////////////////////
// 1. super init first
if ( !BaseLayer::init() )
{
return false;
}
SimpleAudioEngine::sharedEngine()->preloadEffect("sfx_cursor_back.wav");
SimpleAudioEngine::sharedEngine()->preloadEffect("sfx_cursor_move.wav");
SimpleAudioEngine::sharedEngine()->preloadEffect("sfx_cursor_select.wav");
SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("logos.plist");
SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("chars.plist");
SpriteBatchNode *mainBatchNode = SpriteBatchNode::create("chars.png");
Sprite *bg = Sprite::create("bg_menu.png");
bg->getTexture()->setAliasTexParameters();
bg->setAnchorPoint(ccp(0, 0));
bg->setPosition(ccp(0, 0));
Sprite *gameLogo = Sprite::createWithSpriteFrameName("game_logo.png");
gameLogo->getTexture()->setAliasTexParameters();
gameLogo->setAnchorPoint(ccp(0.5f, 0.5f));
gameLogo->setPosition(ccp(80, 103));
pressStartLabel = LabelBMFont::create("PRESS START", "whitefont.fnt", 160, kTextAlignmentCenter);
pressStartLabel->setColor(gbLightestColor3);
pressStartLabel->getTexture()->setAliasTexParameters();
pressStartLabel->setAnchorPoint(ccp(0.5f, 0.5f));
pressStartLabel->setPosition(ccp(80, 30));
startGameLabel = LabelBMFont::create("Start game", "whitefont.fnt", 160, kTextAlignmentCenter);
startGameLabel->setColor(gbLightColor3);
startGameLabel->getTexture()->setAliasTexParameters();
startGameLabel->setAnchorPoint(ccp(0.5f, 0.5f));
startGameLabel->setPosition(ccp(80, 30));
creditsLabel = LabelBMFont::create("Credits", "whitefont.fnt", 160, kTextAlignmentCenter);
creditsLabel->setColor(gbLightColor3);
creditsLabel->setAnchorPoint(ccp(0.5f, 0.5f));
creditsLabel->setPosition(ccp(80, 30));
levelLabel = LabelBMFont::create("Level", "whitefont.fnt", 78, kTextAlignmentRight);
levelLabel->setColor(gbLightColor3);
levelLabel->setAnchorPoint(ccp(1.0f, 0.5f));
levelLabel->setPosition(ccp(78, 30));
levelNumberLabel = LabelBMFont::create("1", "whitefont.fnt", 78, kTextAlignmentLeft);
levelNumberLabel->setColor(gbLightColor3);
levelNumberLabel->setAnchorPoint(ccp(0.0f, 0.5f));
levelNumberLabel->setPosition(ccp(82, 30));
arrowUp = Sprite::createWithSpriteFrameName("arrowup.png");
arrowUp->setAnchorPoint(ccp(0.5f, 0.0f));
arrowUp->getTexture()->setAliasTexParameters();
arrowDown = Sprite::createWithSpriteFrameName("arrowdown.png");
arrowDown->setAnchorPoint(ccp(0.5f, 1.0f));
mainBatchNode->addChild(arrowUp);
mainBatchNode->addChild(arrowDown);
this->addChild(bg);
this->addChild(gameLogo);
this->addChild(pressStartLabel);
this->addChild(startGameLabel);
this->addChild(creditsLabel);
this->addChild(levelLabel);
this->addChild(levelNumberLabel);
this->addChild(mainBatchNode);
optionIndex = 0;
cursorIndex = 0;
maxLevel = UserDefault::sharedUserDefault()->getIntegerForKey("MaxLevel", 1);
if (maxLevel > kLastLevel) maxLevel = kLastLevel;
selectedLevel = maxLevel;
this->updateMenu();
if (!SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
SimpleAudioEngine::sharedEngine()->playBackgroundMusic("song_title.wav", true);
return true;
}