//初始化,添加元素
_asteroids = new CCMutableArray<CCSprite *>();
for(int i = 0; i < KNUMASTEROIDS; ++i) {
CCSprite *asteroid = CCSprite::spriteWithSpriteFrameName("asteroid.png");
asteroid->setIsVisible(false) ;
_batchNode->addChild(asteroid);
_asteroids->addObject(asteroid);
}
//update方法里刷新
float randMillisecs = randomValueBetween(0.20,1.0) * 1000;
_nextAsteroidSpawn = randMillisecs + curTimeMillis;
float randY = randomValueBetween(0.0,winSize.height);
float randDuration = randomValueBetween(2.0,10.0);
CCSprite *asteroid = (CCSprite *)(_asteroids->getObjectAtIndex(_nextAsteroidSpawn));
cout<<_asteroids->getObjectAtIndex(_nextAsteroidSpawn)<<endl;//输出全部是0
_nextAsteroidSpawn++;
if (_nextAsteroidSpawn >= _asteroids->count())
_nextAsteroidSpawn = 0;
if (asteroid) {//都是空,下面不执行
asteroid->stopAllActions();
asteroid->setPosition( ccp(winSize.width+asteroid->getContentSize().width/2, randY));
asteroid->setIsVisible(true) ;
asteroid->runAction ( CCSequence::actions ( CCMoveBy::actionWithDuration(randDuration,ccp(-winSize.width-asteroid->getContentSize().width,0)) ,
CCCallFuncN::actionWithTarget(this,callfuncN_selector(HelloWorld::setInvisible)) ,
NULL // DO NOT FORGET TO TERMINATE WITH NULL (unexpected in C++)
) ) ;
}
asteroid.png确实是有的,请问是什么问题?