Frage

i need help? how to remove this error please help to fix me and how add sprites in this array..As i tired with spritesWithfile and NsmutableArray is not working in cocos2d 2.2.0.4 so please let me know

cocos2d::CCArray *arr;  
cocos2d::CCSprite *foo;  
arr->addObject(foo);

CCObject *item;
CCARRAY_FOREACH(arr, item) // here i am getting error as no member 'data' is present in                   cocos2d::ccsprite
{
  // i have left blank in my code 
}
War es hilfreich?

Lösung

So you are trying to create an array of CCSprite*?

I dont have 2.0.4 documentation handy to tell you what default constructors you could take advantage of. so I'll do it a way I know will work.

cocos2d::CCArray* arr = new CCAray();

for (int i=0, i < 5; i++)
{
    CCSprite* foo = new cocos2d::CCSprite(); 
    foo->initWithFile( "sprite.png" );

    arr->addObject(foo);
}

I dont prefer CCArray, I just use an std::vector.

std::vector<CCSprite*> _sprites;
_sprites.reserve(<some initial amount>); // if this makes sense for you.

for (int i=0, i < 5; i++)
{
    CCSprite* foo = new cocos2d::CCSprite(); 
    foo->initWithFile( "sprite.png" );

    v.push_back(foo);
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top