本文整理汇总了C++中CCSpriteBatchNode::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ CCSpriteBatchNode::addChild方法的具体用法?C++ CCSpriteBatchNode::addChild怎么用?C++ CCSpriteBatchNode::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCSpriteBatchNode
的用法示例。
在下文中一共展示了CCSpriteBatchNode::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initMapNode
void GameLayer::initMapNode(CCNode *node)
{
// window size
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
// use batchnode to reduce rendering
CCSpriteBatchNode *batchNode = CCSpriteBatchNode::create("GameScene.pvr.ccz");
node->addChild(batchNode, 0, MapBatchNodeTag);
// add background
CCSprite *backgroundSprite = CCSprite::createWithSpriteFrameName("Background.png");
backgroundSprite->setPosition(ccp(winSize.width/2.f, winSize.height/2.f));
batchNode->addChild(backgroundSprite);
// add glass road
CCSprite *glassRoadSprite = CCSprite::createWithSpriteFrameName("Road.png");
glassRoadSprite->setPosition(ccp(winSize.width/2.f, winSize.height/2.f));
batchNode->addChild(glassRoadSprite);
// add monster
CCSprite *monsterSprite = CCSprite::createWithSpriteFrameName("Monster.png");
batchNode->addChild(monsterSprite, 0, MapMonsterTag);
// add river
CCSprite *riverSprite = CCSprite::createWithSpriteFrameName("River.png");
batchNode->addChild(riverSprite, 0, MapRiverTag);
// add coins
for (int i = 0; i < kGameCoinCount; i ++) {
CCSprite *coinSprite = CCSprite::createWithSpriteFrameName("Gold.png");
batchNode->addChild(coinSprite, 0, MapCoinStartTag + i);
}
}
示例2: MapShowHPOffset
void BattleCharacter::MapShowHPOffset(int dam)
{
CCSpriteBatchNode* pNumBatchNode = (CCSpriteBatchNode*)m_pMap->getChildByTag(LAYER_MAPNUMS_ID);
CCArray* numSprites = NULL;
if (dam<0)
{
numSprites = AnimationManager::instance()->CreateSizeNums(-dam,NUMS_SMALL_RED);
}
else
{
numSprites = AnimationManager::instance()->CreateSizeNums(dam,NUMS_SMALL_BLACK);
}
unsigned int count = numSprites->count();
//计算当前前数字个数,决定显示位置的偏移量。当个数为奇数时,不做办个数字的偏移。当数字为偶数时,需要向右偏移半个数字精灵的图片宽度。
float distance = NUMS_SMALL_DISTANCE;
float half = count%2==0?0:distance/2;
for(unsigned int index = 0;index<count;index++)
{
CCSprite* numSprite = (CCSprite*)numSprites->objectAtIndex(index);
pNumBatchNode->addChild(numSprite,MAX_LAYER_ZORDER);
numSprite->setPosition(ccp(GetMapPositionX()+half+(count/2-index)*distance,GetMapPositionY()));
numSprite->runAction(CCSequence::createWithTwoActions(CCMoveBy::create(NUMS_MAPFALL_DUR,ccp(0,SQUARE_LENTH/2)),CCCallFuncND::create(this,callfuncND_selector(AnimationManager::RemoveAniamationSprite),(void*)numSprite)));
}
}
示例3: loadUI
void SpriteBatchNodeTestPage::loadUI()
{
setTouchEnabled(true);
setTouchMode(kCCTouchesOneByOne);
auto winSize = CocosWindow::size();
auto origin = CocosWindow::origin();
const std::string pic("Images/grossini_dance_01.png");
size_t num(1000);
/*for (size_t i=0; i<num; ++i)
{
auto dance = CCSprite::create(pic.c_str());
CCPoint pos;
pos.x = winSize.width * CCRANDOM_0_1();
pos.y = winSize.height * CCRANDOM_0_1();
dance->setPosition(pos);
addChildRaw(dance);
}*/
CCSpriteBatchNode *batch = CCSpriteBatchNode::create(pic.c_str());
for (size_t i=0; i<num; ++i) {
auto dance = CCSprite::createWithTexture(batch->getTexture());
CCPoint pos;
pos.x = winSize.width * CCRANDOM_0_1();
pos.y = winSize.height * CCRANDOM_0_1();
dance->setPosition(pos);
batch->addChild(dance);
}
ADD_CHILD(batch);
}
示例4:
bool Recipe30::init()
{
if ( !RecipeBase::init() )
{
return false;
}
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSpriteBatchNode* pBatchNode = CCSpriteBatchNode::create("recipe30_uhhoi.png");
this->addChild(pBatchNode);
for (int i=0; i<300; i++) {
CCSprite* sprite = CCSprite::createWithTexture(pBatchNode->getTexture());
float x = CCRANDOM_0_1()*size.width;
float y = CCRANDOM_0_1()*size.height;
sprite->setPosition(ccp(x, y));
pBatchNode->addChild(sprite);
CCFadeOut* fade = CCFadeOut::create(CCRANDOM_0_1()*10.0f);
sprite->runAction(fade);
}
return true;
}
示例5: ccp
bool T08CCSpriteBatchNode::init()
{
if (!BaseLayer::init())
return false;
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCPoint ptCenter = ccp(winSize.width / 2, winSize.height / 2);
/*
CCSpriteBatchNode是一个容器,只能包容CCSprite对象,要求这些精灵来自同一个纹理
*/
CCSpriteBatchNode* pBatch = CCSpriteBatchNode::create("CloseNormal.png");
addChild(pBatch);
pBatch->setTag(10);
CCSprite *pSprite = CCSprite::createWithTexture(pBatch->getTexture());
pBatch->addChild(pSprite);
pSprite->setPosition(ptCenter);
setTouchEnabled(true);
setTouchMode(kCCTouchesOneByOne);
return true;
}
示例6: CCRectMake
void Box2DTestLayer::addNewSpriteWithCoords(CCPoint p)
{
//UXLOG(L"Add sprite %0.2f x %02.f",p.x,p.y);
CCSpriteBatchNode* sheet = (CCSpriteBatchNode*)getChildByTag(kTagSpriteManager);
//We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is
//just randomly picking one of the images
int idx = (CCRANDOM_0_1() > .5 ? 0:1);
int idy = (CCRANDOM_0_1() > .5 ? 0:1);
CCSprite *sprite = sheet->createSpriteWithRect( CCRectMake(32 * idx,32 * idy,32,32));
sheet->addChild(sprite);
sprite->setPosition( CCPointMake( p.x, p.y) );
// Define the dynamic body.
//Set up a 1m squared box in the physics world
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
bodyDef.userData = sprite;
b2Body *body = world->CreateBody(&bodyDef);
// Define another box shape for our dynamic body.
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box
// Define the dynamic body fixture.
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.3f;
body->CreateFixture(&fixtureDef);
}
示例7: initPlayer
void GameLayer::initPlayer()
{
CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
frameCache->addSpriteFramesWithFile("LuckyFlying.plist");
CCSpriteBatchNode* pigeonFlightSheet = CCSpriteBatchNode::create("LuckyFlying.png");
addChild(pigeonFlightSheet, 3);
CCArray* pigeonFrames = new CCArray;
for ( int i = 2; i <= 4; i++)
{
CCString* filename = CCString::createWithFormat("lucky_flying_0000%d.png", i);
CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(filename->getCString());
pigeonFrames->addObject(frame);
}
CCAnimation* flightAnim = CCAnimation::createWithSpriteFrames(pigeonFrames, 0.1);
pigeonSprite = CCSprite::createWithSpriteFrameName("lucky_flying_00002.png");
//pigeonSprite->setScale(0.5f);
pigeonSprite->setPosition(ccp(SCREEN_WIDTH/2 - 500, SCREEN_WIDTH*3 + 250));
CCAction* flightAction = CCRepeatForever::create(CCAnimate::create(flightAnim));
pigeonSprite->runAction(flightAction);
pigeonFlightSheet->addChild(pigeonSprite, 3);
schedule(schedule_selector(GameLayer::tick1), 0.10f);
schedule(schedule_selector(GameLayer::tick2), 0.03f);
}
示例8: AddCartchSprite
//------------------------------------------------------------------------------
//
//
void CMiniGameCatchLayer::AddCartchSprite(CCPoint p)
{
//UXLOG(L"Add sprite %0.2f x %02.f",p.x,p.y);
CCSpriteBatchNode *mgr = (CCSpriteBatchNode*)getChildByTag( kTagSpriteManager );
int index = 1 + (int)(CCRANDOM_0_1() * 11);
int pixScale = 1;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
if( CDevice::GetDeviceType() == "iPad" )
{
pixScale = 2;
}
#endif
CCRect rect( ( index % 4) * 32 * pixScale, index / 4 * 32 * pixScale ,32 * pixScale, 32 * pixScale );
CCSprite *sprite = CCSprite::spriteWithBatchNode( mgr, rect );
// addChild(sprite, MINIGAME_LAYER_BEGIN);
sprite->setPosition( CCPointMake( p.x, p.y) );
sprite->setTag( index );
mgr->addChild( sprite );
//sprite->setAnchorPoint(ccp( 0,0 ));
// Define the dynamic body.
//Set up a 1m squared box in the physics world
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
bodyDef.userData = sprite;
b2Body *body = world->CreateBody(&bodyDef);
// Define another box shape for our dynamic body.
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(32.0f/ PTM_RATIO / 2.0f, 32.0f/ PTM_RATIO / 2.0f);//These are mid points for our 1m box
// Define the dynamic body fixture.
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 5.0f;
fixtureDef.friction = 0.3f;
body->CreateFixture(&fixtureDef);
CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
b2Vec2 d;
srand( GetCurrentSeconds() );
d.Set( rand() % 10 * screenSize.width / 10.f, screenSize.height + screenSize.height );
d.Normalize();
b2Vec2 F = 80 * d;
body->ApplyForce(F,d);
}
示例9: performAnimation
void Object::performAnimation(string name, SEL_CallFunc func){
if (this->getCurrentObjectState() == ObjectStateDead && name.compare("Dead") != 0) {
return;
}
CCSpriteBatchNode *currentSpriteBatchNode = m_pobBatchNode;
CCSpriteBatchNode *newSpriteBatchNode = NULL;
// Get the action pair by key name
CCArray *actionPair = (CCArray *)actionsHashes->objectForKey(name);
// If the action pair does not exist, return early
if (!actionPair) {
return;
}
newSpriteBatchNode = (CCSpriteBatchNode *)actionPair->objectAtIndex(1);
ActionNode *actionNode = (ActionNode *)actionPair->objectAtIndex(0);
this->stopActionByTag(ACTION_ANIMATION_TAG);
// If required spriteBatchNode is different from current, replace it
if (currentSpriteBatchNode != newSpriteBatchNode) {
this->removeFromParentAndCleanup(false);
this->setTexture(actionNode->getFirstSpriteFrame()->getTexture());
this->setTextureRect(actionNode->getFirstSpriteFrame()->getRect());
newSpriteBatchNode->addChild(this);
}
if (func != NULL) {
CCAssert(dynamic_cast<CCRepeatForever*>(actionNode->getAnimation()) == NULL, "Not able to call function for CCRepeatForever action.");
// Create animation followed by a function call
CCSequence *seq = CCSequence::createWithTwoActions(actionNode->getAnimation(), CCCallFunc::create(this, func));
seq->setTag(ACTION_ANIMATION_TAG);
this->runAction(seq);
} else {
// Run the action
actionNode->getAnimation()->setTag(ACTION_ANIMATION_TAG);
this->runAction(actionNode->getAnimation());
}
// Run AI in this action
{
if (actionPair->count() > 2) {
CCArray *AIActions = (CCArray *)actionPair->objectAtIndex(2);
CCLOG("%s is running AI, total AIAction count: %d", identifier.c_str(), AIActions->count());
for (int i = 0; i < AIActions->count(); i++) {
CCAction *action = (CCAction*)AIActions->objectAtIndex(i);
this->runAction(action);
}
}
}
}
示例10: initBarrierNode
void GameLayer::initBarrierNode(CCNode *node)
{
// window size
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
// use batchnode to reduce rendering
CCSpriteBatchNode *batchNode = CCSpriteBatchNode::create("GameScene.pvr.ccz");
node->addChild(batchNode, 0, MapBatchNodeTag);
// add barrier
CCSprite *barrierSprite = CCSprite::createWithSpriteFrameName("Barrier.png");
batchNode->addChild(barrierSprite, 0, MapBarrierTag);
}
示例11: createFish
void SoulPrev::createFish(const CCPoint& point) {
//use CCSpriteBachNode to draw texture
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->textureForKey("fish.png");
CCSpriteBatchNode* spbatch = CCSpriteBatchNode::createWithTexture(texture);
spbatch->setPosition(ccp(0, 0));
this->addChild(spbatch);
CCSprite* sprite = CCSprite::createWithSpriteFrameName("hudieyu_72.png");
sprite->setPosition(point);
sprite->setPosition(point);
spbatch->addChild(sprite);
}
示例12:
bool T08CCSpriteBatchNode::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCSpriteBatchNode* pBatch = (CCSpriteBatchNode*)getChildByTag(10);
for (int i = 0; i < 1000; i++) {
CCSprite* pSprite = CCSprite::create("CloseNormal.png");
pBatch->addChild(pSprite);
pSprite->setPosition(ccp(CCRANDOM_0_1()*winSize.width, CCRANDOM_0_1()*winSize.height));
}
return true;
}
示例13:
CCNode *APSSprite::createNode() {
CCNode *node = APSGraphic::createNode();
APSImageHolder *ih = this->getImageHolder();
CCSize contentSize;
CCSize targetSize = APSPlatform::sharedPlatform()->convertSizeToPixels(this->getSize());
if (ih) {
this->m_spriteNode = new CCSprite;
if (this->getIsAnimatable()) {
// Create animation sprite
APSSpriteSheetHolder *sh = (APSSpriteSheetHolder *)ih;
CCSpriteFrame *spriteFrame = sh->getCCSpriteFrameAtIndex(((APSGraphicGroup *)this->getParent())->getDisplayedFrameIndex());
#if COCOS2D_VERSION >= 0x00020000
CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::createWithTexture(ih->getTexture(), sh->getCount());
#else
CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::batchNodeWithTexture(ih->getTexture(), sh->getCount());
#endif//APS_SKIP
this->m_node->addChild(spriteSheet);
this->m_spriteNode->initWithSpriteFrame(spriteFrame);
spriteSheet->addChild(this->m_spriteNode);
CCSize size = this->m_spriteNode->getContentSize();
contentSize = APSPlatform::sharedPlatform()->convertSizeToPixels(size);
} else {
// Check if there is a sprite frame in sprite frame cache.
CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(this->getImageHolder()->getRuntimeFilename().c_str());
if (frame) {
// Use the sprite frame
this->m_spriteNode->initWithSpriteFrame(frame);
contentSize = frame->getOriginalSizeInPixels();
node->addChild(this->m_spriteNode);
} else {
// Normal sprite
this->m_spriteNode->initWithTexture(ih->getTexture());
contentSize = ih->getTexture()->getContentSizeInPixels();
node->addChild(this->m_spriteNode);
}
}
// scale the sprite to match the sizes of texture and sprite
this->m_spriteNode->setScaleX(targetSize.width/contentSize.width);
this->m_spriteNode->setScaleY(targetSize.height/contentSize.height);
}
return node;
}
示例14: loadEnemys
void EnemyPlaneLayer::loadEnemys()
{
//当一批飞机全部添加后,此批敌机没有被消灭干净前,不再增加下批敌机
if((EnemyPlane::_enemyPlanes.count() > 0)){
delayTimerCallLoadEnemys(1.0f);
return;
}
static int batchIndex = 0; //第几批敌机
float aircraftTimeSum = 0; //每批敌机出场时间和
//当前批敌机数组
CCArray* batchEnemys = dynamic_cast<CCArray*>(m_enemyPlanesArray.objectAtIndex(batchIndex));
CCObject* obj = NULL;
CCARRAY_FOREACH(batchEnemys,obj){
CCDictionary* enemyDict = dynamic_cast<CCDictionary*>(obj);
//当前敌机属性字典,获取敌机出场时间
GameObjectPool* factory = EnemyPlaneFactory::shareEnemyPlaneFactory();
EnemyPlane* enemyPlane = NULL;
if(factory)
{
enemyPlane = dynamic_cast<EnemyPlane*>(factory->getObject(enemyDict));
//调式用的全局敌机变量
_enemyPlane = enemyPlane;
//设置被碰撞粒子效果的文件名
enemyPlane->setHitParticleName(NORMAL_HIT_PARTICLE_PLIST);
//粒子效果的父层需要是非批渲染层
enemyPlane->setBatchParticleNodesParent(this);
//计算出场时间之和
aircraftTimeSum += enemyPlane->getAircraftTime();
//计算出场位置
srand((unsigned) time(NULL));
float t = enemyPlane->getScale();
int t1 = rand();
float widthRange = CCDirector::sharedDirector()->getWinSize().width -
enemyPlane->boundingBox().size.width * enemyPlane->getScale();
float startPositionX = enemyPlane->boundingBox().size.width / 2 * enemyPlane->getScale() + rand() % int(widthRange);
float startPositionY = CCDirector::sharedDirector()->getWinSize().height +
enemyPlane->boundingBox().size.height * enemyPlane->getScale() + 10;
startPositionX = CCDirector::sharedDirector()->getWinSize().width / 2;
enemyPlane->setPosition(ccp(startPositionX,startPositionY));
enemyPlane->prepareFly();
CCSpriteBatchNode* batchNode = AppConfig::shareAppConfig()->getGlobalBatchNode();
enemyPlane->setBullteFlySpace(batchNode);
batchNode->addChild(enemyPlane,ENEMY_PLANE_ZORDER);
}
}
示例15: _initPlatform
void GameLayer::_initPlatform()
{
CCRect rect;
switch((int)CCRANDOM_0_1() * 2)
{
case 0:
rect = CCRectMake(608, 64, 102, 36);
break;
case 1:
rect = CCRectMake(608, 128, 90, 32);
break;
}
CCSpriteBatchNode* batchNode = dynamic_cast<CCSpriteBatchNode*>(getChildByTag(kSpriteManager));
CCSprite* platform = CCSprite::createWithTexture(batchNode->getTexture(), rect);
batchNode->addChild(platform, 3, currentPlatformTag);
}