本文整理汇总了C++中CCArray::addObject方法的典型用法代码示例。如果您正苦于以下问题:C++ CCArray::addObject方法的具体用法?C++ CCArray::addObject怎么用?C++ CCArray::addObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCArray
的用法示例。
在下文中一共展示了CCArray::addObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sprintf
TeslaItem::TeslaItem(const int id, const int friendId)
:MovingObstacle(id),
_friendId(friendId)
{
CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
this->initWithSpriteFrameName("teslaItem1.png");
CCArray* animFrames = CCArray::createWithCapacity(10);
char str[100] = {0};
for (int i = 0; i < 30; ++i) {
int animNumber = i < 15 ? i + 1 : 30 - i;
sprintf(str, "teslaItem%d.png", animNumber);
CCSpriteFrame* frame = cache->spriteFrameByName(str);
animFrames->addObject(frame);
}
CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames);
animation->setDelayPerUnit(1 / 30.0f);
CCAnimate* animate = CCAnimate::create(animation);
this->runAction(CCRepeatForever::create(animate));
}
示例2: runFullAnimation
void Image::runFullAnimation(float delay, bool invert)
{
CCAssert(spriteSheet != NULL, "Image runFullAnimation called on an object without spritesheet");
CCArray* animationFrames = CCArray::createWithCapacity(spritesName->count());
for(int i = 0; i < spritesName->count(); i++)
{
CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(((CCString*)spritesName->objectAtIndex(invert ? spritesName->count() - i - 1 : i))->getCString());
CCAnimationFrame* frame = new CCAnimationFrame();
frame->initWithSpriteFrame(spriteFrame, 1, NULL);
frame->autorelease();
animationFrames->addObject(frame);
}
CCAction* action = CCRepeatForever::create(CCAnimate::create(CCAnimation::create(animationFrames, delay)));
if(runningAnimation != action)
{
if(runningAnimation != NULL)
{
delegate->stopAction(runningAnimation);
}
delegate->runAction(action);
runningAnimation = action;
}
}
示例3: textHandler
void textHandler(void *ctx, const char *ch, int len)
{
CC_UNUSED_PARAM(ctx);
if (m_tState == SAX_NONE)
{
return;
}
CCSAXState curState = m_tStateStack.empty() ? SAX_DICT : m_tStateStack.top();
CCString *pText = new CCString();
pText->m_sString = std::string((char*)ch,0,len);
switch(m_tState)
{
case SAX_KEY:
m_sCurKey = pText->m_sString;
break;
case SAX_INT:
case SAX_REAL:
case SAX_STRING:
{
if (SAX_ARRAY == curState)
{
m_pArray->addObject(pText);
}
else if (SAX_DICT == curState)
{
CCAssert(!m_sCurKey.empty(), "not found key : <integet/real>");
m_pCurDict->setObject(pText, m_sCurKey);
}
break;
}
default:
break;
}
pText->release();
}
示例4: init
// on "init" you need to initialize your instance
bool Game::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
loadBg();
loadCards();
CCSize size = CCDirector::sharedDirector()->getWinSize();
char name[20];
CCSpriteFrameCache* cache =CCSpriteFrameCache::sharedSpriteFrameCache();
CCArray * sArr = CCArray::create();
for(int i=1;i<14;i++){
sprintf(name,"FP%d.BMP",i);
CCSpriteFrame* frame =cache->spriteFrameByName(name);
CardSprite* sprite =CardSprite::createWithFrame(frame);
sprite->setPosition(ccp(-50,-50));
sprite->setTag(i);
sArr->addObject(sprite);
addChild(sprite);
}
CCObject* pObj;
int i=1;
CCARRAY_FOREACH(sArr, pObj)
{
CardSprite* cs = (CardSprite*)pObj;
CCActionInterval *actionTo = CCMoveTo::create(4.0f,
ccp(140+i*25,size.height/4));
cs->runAction(actionTo);
i++;
}
示例5: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
glClearColor(1, 1, 1, 1);
CCSprite *sprite = CCSprite::create("CloseNormal.png");
this->addChild(sprite);
sprite->setPosition(ccp(240, 160));
sprite->setScale(2.f);
CCSize ss = sprite->getContentSize();
CCOrbitCamera *orbit = CCOrbitCamera::create(5.f, 5.f, 0, 0, 360, 90, -45);
CCMoveBy *moveBy = CCMoveBy::create(5.f, ccp(100, 0));
sprite->runAction(CCSequence::create(orbit,moveBy));
CCArray *array = CCArray::create();
array->addObject(this);
CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(HelloWorld::updateabc), this, 2.f, false);
CCMenuItemImage *i = CCMenuItemImage::create("CloseNormal.png", NULL, this, menu_selector(HelloWorld::clicked));
CCMenu *menu = CCMenu::create(i,NULL);
menu->setPosition(100, 100);
this->addChild(menu);
CCTexture2D *t = WGDirector::textureWithCString("Map_6.png");
CCSprite *sp = CCSprite::createWithTexture(t);
this->addChild(sp);
return true;
}
示例6: loadProducts
void INSPayment_iOS::loadProducts(inewsoft::ol::LoadProductCallback callback)
{
if(!this->productTable.empty() && productsState == inewsoft::ol::kProductsStateLoaded)
{
callback(true);
return;
}
else if(this->productsState == inewsoft::ol::kProductsStateLoading)
{
this->loadProductCallback = callback;
return;
}
/// loald product from developer server firstly
this->productsState = inewsoft::ol::kProductsStateLoading;
Payment::loadProducts([this, callback](bool succeed){
if(succeed) {
INSStore::sharedStore()->registerTransactionObserver(this);
CCArray* productsId = new CCArray();
productsId->autorelease();
for(auto iter = this->productTable.begin(); iter != this->productTable.end(); ++iter)
{
productsId->addObject(newCCString(iter->second.id.c_str()));
}
this->loadProductCallback = callback;
INSStore::sharedStore()->loadProducts(productsId, this);
}
else {
this->productsState = inewsoft::ol::kProductsStateUnload;
callback(false);
}
});
}
示例7: ccp
//构造函数
Ship::Ship()
{
this->speed = 220;
this->bulletSpeed = 900;
this->HP = 5;
this->bulletTypeValue = 1;
this->bulletPowerValue = 1;
this->throwBombing = false;
this->canBeAttack = true;
this->isThrowingBomb = false;
this->zOrder = 3000;
this->maxBulletPowerValue = 4;
this->appearPosition = ccp(160, 60);
this->hurtColorLife = 0;
this->active = true;
this->timeTick = 0;
this->initWithSpriteFrameName("ship01.png");
this->setTag(zOrder);
this->setPosition(this->appearPosition);
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
CCSpriteFrame *frame0 = cache->spriteFrameByName("ship01.png");
CCSpriteFrame *frame1 = cache->spriteFrameByName("ship02.png");
CCArray *frames = CCArray::createWithCapacity(2);
frames->addObject(frame0);
frames->addObject(frame1);
CCAnimation *animation = CCAnimation::createWithSpriteFrames(frames, 0.1f);
CCAnimate *animate = CCAnimate::create(animation);
this->runAction(CCRepeatForever::create(animate));
this->schedule(schedule_selector(Ship::shoot),0.2f);
this->born();
}
示例8: loadCardsFromXml
void CardScene::loadCardsFromXml()
{
TiXmlDocument doc;
//list of card for scroll layer init
CCArray* cardList = CCArray::create();
if ( doc.LoadFile(CARDS_XML) )
{
TiXmlElement* cards_tag = doc.FirstChildElement();
TiXmlElement* card_tag = cards_tag->FirstChildElement();
while ( card_tag )
{
int number = 0;
card_tag->QueryIntAttribute("number", &number);
const char* path = card_tag->Attribute("path");
const char* description_id = card_tag->Attribute("description_id");
//TODO: load description from L10n(Localization) file with description_id
//create card and add to card list
Card* card = Card::create(number, path, description_id);
cardList->addObject( card );
card_tag = card_tag->NextSiblingElement();
}
}
m_pScrollList = CCScrollLayer::create(cardList);
m_pScrollList->setPosition( ccp(0, 0) );
addChild( m_pScrollList );
}
示例9: if
//------------------------------------------------------------------------------
CCArray* LHLayer::spritesWithTag(int tag){
#if COCOS2D_VERSION >= 0x00020000
CCArray* array = CCArray::create();
#else
CCArray* array = CCArray::array();
#endif
CCArray* children = getChildren();
for(int i = 0; i < children->count(); ++i){
CCNode* node = (CCNode*)children->objectAtIndex(i);
if(LHSprite::isLHSprite(node)){
if(node->getTag() == tag)
array->addObject(node);
}
else if(LHBatch::isLHBatch(node)){
array->addObjectsFromArray(((LHBatch*)node)->spritesWithTag(tag));
}
else if(LHLayer::isLHLayer(node)){
array->addObjectsFromArray(((LHLayer*)node)->spritesWithTag(tag));
}
}
return array;
}
示例10: createHeroMovingAnimationByDirection
CCAnimation* AnimationManager::createHeroMovingAnimationByDirection(HeroDirection direction)
{
CCTexture2D *heroTexture = CCTextureCache::sharedTextureCache()->addImage("Hero_image.png");
CCSpriteFrame *frame0, *frame1, *frame2;
CCArray* animFrames ;
//第二个参数表示显示区域的x, y, width, height,根据direction来确定显示的y坐标
frame0 = CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(eSize*0, eSize*direction, eSize, eSize));
frame1 = CCSpriteFrame::createWithTexture(heroTexture, cocos2d::CCRectMake(eSize*1, eSize*direction, eSize, eSize));
animFrames = new CCArray(2);
animFrames->addObject(frame0);
animFrames->addObject(frame1);
CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames, 0.09f);
animFrames->release();
return animation;
}
示例11: SpawnCrow
void Obstacle::SpawnCrow(int xOffset)
{
CCArray *allFrames = new CCArray();
for (int i = 0 ; i <= 14 ; i++)
{
char fn[64];
sprintf(fn, "Fly00%d.png" , i );
allFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fn));
}
CCAnimation *crowAnim = CCAnimation::createWithSpriteFrames(allFrames, 0.04f * 1);
CCAction *crowAction = CCRepeatForever::create(CCAnimate::create(crowAnim));
crowAction->retain();
obstacleSprite = CCSprite::createWithSpriteFrameName("Fly000.png");
obstacleSprite->setPosition(ccp(winSize.width + xOffset * SPAWN_OFFSET , winSize.height - obstacleSprite->getContentSize().height));
this->addChild(obstacleSprite);
obstacleSprite->runAction(crowAction);
moveOnce = true;
// obstacleSprite->runAction(CCSequence::createWithTwoActions(CCMoveTo::create(1,
// ccp( winSize.width - obstacleSprite->getContentSize().width , obstacleSprite->getPosition().y)),
// CCCallFunc::create(this, callfunc_selector(Obstacle::MoveCrow))));
}
示例12: createAnimWithFrameNameAndNum
CCAnimation* AnimationUtil::createAnimWithFrameNameAndNum( const char* name, int iNum, float delay, unsigned int iLoops) {
CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
CCArray* framesArray = CCArray::create();
CCSpriteFrame* frame = NULL;
int index = 1;
for(int i = 1; i <= iNum; i++) {
frame = cache->spriteFrameByName(CCString::createWithFormat("%s%d.png", name, i)->getCString());
if(frame == NULL) {
break;
}
framesArray->addObject(frame);
}
CCAnimation* animation = CCAnimation::createWithSpriteFrames(framesArray);
animation->setLoops(iLoops);
animation->setRestoreOriginalFrame(true);
animation->setDelayPerUnit(delay);
return animation;
}
示例13: goToMapScene
//public
void RPGStartSceneLayer::goToMapScene()
{
CCArray *loadTextures = CCArray::create();
loadTextures->addObject(CCString::create("map.png"));
loadTextures->addObject(CCString::create("main.png"));
loadTextures->addObject(CCString::create("joystick.png"));
loadTextures->addObject(CCString::create("actor4_0.png"));
loadTextures->addObject(CCString::create("actor111.png"));
loadTextures->addObject(CCString::create("actor113.png"));
loadTextures->addObject(CCString::create("actor114.png"));
loadTextures->addObject(CCString::create("actor115.png"));
loadTextures->addObject(CCString::create("actor117.png"));
loadTextures->addObject(CCString::create("actor120.png"));
CCMenu *mainMenu = (CCMenu*)this->getChildByTag(kRPGStartSceneLayerTagMainMenu);
mainMenu->setEnabled(false);
CCScene *s = RPGLoadingSceneLayer::scene(loadTextures, NULL, "single_map");
CCTransitionFade *t = CCTransitionFade::create(GAME_SCENE, s);
CCDirector::sharedDirector()->replaceScene(t);
}
示例14: init
void Effect::init(int type)
{
effectid=type;
switch (type)
{
case 1:
{
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("effect1.plist");
CCArray *animFrames = CCArray::create();
firtPngName="1000.png";
effectName="effect1";
char str[64] = {0};
for (int i = 0; i <6; ++i)
{
sprintf(str, "100%d.png", i);
CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str);
animFrames->addObject(frame);
}
CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.1);
// 帧动画命名
CCAnimationCache::sharedAnimationCache()->addAnimation(animation,effectName.c_str());
break;
}
case 2:
{
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("effect2.plist");
CCArray *animFrames = CCArray::create();
firtPngName="2000.png";
effectName="effect2";
char str[64] = {0};
for (int i = 0; i <2; ++i)
{
sprintf(str, "200%d.png", i);
CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str);
animFrames->addObject(frame);
}
CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.1);
// 帧动画命名
CCAnimationCache::sharedAnimationCache()->addAnimation(animation,effectName.c_str());
break;
}
case 3:
{
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("effect3.plist");
CCArray *animFrames = CCArray::create();
firtPngName="3000.png";
effectName="effect3";
char str[64] = {0};
for (int i = 0; i <1; ++i)
{
sprintf(str, "300%d.png", i);
CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str);
animFrames->addObject(frame);
}
CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.1);
// 帧动画命名
CCAnimationCache::sharedAnimationCache()->addAnimation(animation,effectName.c_str());
break;
}
case 4:
{
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("effect4.plist");
CCArray *animFrames = CCArray::create();
firtPngName="4000.png";
effectName="effect4";
char str[64] = {0};
for (int i = 0; i <1; ++i)
{
sprintf(str, "400%d.png", i);
CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str);
animFrames->addObject(frame);
}
CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.1);
// 帧动画命名
CCAnimationCache::sharedAnimationCache()->addAnimation(animation,effectName.c_str());
break;
}
case 5:
{
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("effect5.plist");
CCArray *animFrames = CCArray::create();
firtPngName="5000.png";
effectName="effect5";
char str[64] = {0};
for (int i = 0; i <1; ++i)
{
sprintf(str,"500%d.png", i);
CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str);
animFrames->addObject(frame);
}
CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.1);
// 帧动画命名
CCAnimationCache::sharedAnimationCache()->addAnimation(animation,effectName.c_str());
break;
}
case 6:
{
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("effect6.plist");
CCArray *animFrames = CCArray::create();
firtPngName="6000.png";
//.........这里部分代码省略.........
示例15:
CCArray * Utils::getLevelTools(int levelNum) {
CCArray * tools = CCArray::createWithCapacity(14);
switch (levelNum) {
case 1:
{
Bridge * t1 = Bridge::create();
tools->addObject(t1);
}
break;
case 2:
{
Bridge * t1 = Bridge::create();
Bridge * t2 = Bridge::create();
tools->addObject(t1);
tools->addObject(t2);
}
break;
case 3:
{
Bridge * t1 = Bridge::create();
Bridge * t2 = Bridge::create();
Bridge * t3 = Bridge::create();
Bridge * t4 = Bridge::create();
Bridge * t5 = Bridge::create();
tools->addObject(t1);
tools->addObject(t2);
tools->addObject(t3);
tools->addObject(t4);
tools->addObject(t5);
}
break;
case 4:
{
Bridge * t1 = Bridge::create();
Bridge * t2 = Bridge::create();
Bridge * t3 = Bridge::create();
Bridge * t4 = Bridge::create();
tools->addObject(t1);
tools->addObject(t2);
tools->addObject(t3);
tools->addObject(t4);
}
break;
case 5:
{
Spring * t1 = Spring::create();
Spring * t2 = Spring::create();
tools->addObject(t1);
tools->addObject(t2);
}
break;
case 6:
{
Bridge * t1 = Bridge::create();
Bridge * t2 = Bridge::create();
Spring * t3 = Spring::create();
Spring * t4 = Spring::create();
Spring * t5 = Spring::create();
Spring * t6 = Spring::create();
tools->addObject(t1);
tools->addObject(t2);
tools->addObject(t3);
tools->addObject(t4);
tools->addObject(t5);
tools->addObject(t6);
}
break;
case 7:
{
Bridge * t1 = Bridge::create();
Bridge * t2 = Bridge::create();
Spring * t3 = Spring::create();
Spring * t4 = Spring::create();
tools->addObject(t1);
tools->addObject(t2);
tools->addObject(t3);
tools->addObject(t4);
}
break;
case 8:
{
Pole * t1 = Pole::create();
Pole * t2 = Pole::create();
Pole * t3 = Pole::create();
Pole * t4 = Pole::create();
Pole * t5 = Pole::create();
Pole * t6 = Pole::create();
Pole * t7 = Pole::create();
Pole * t8 = Pole::create();
Pole * t9 = Pole::create();
Pole * t10 = Pole::create();
Pole * t11 = Pole::create();
Pole * t12 = Pole::create();
Pole * t13 = Pole::create();
Pole * t14 = Pole::create();
tools->addObject(t1);
tools->addObject(t2);
tools->addObject(t3);
tools->addObject(t4);
tools->addObject(t5);
//.........这里部分代码省略.........