在 cocos2d-x 中使用 CCArray 时遇到问题。我在顶部声明 CCArray *arrCs,在 init() 函数中我为 arrCs 设置了值,但是在我在触摸事件中从它获取值之后,它什么都没有。请帮助我,谢谢大家。
在 MainGame.cpp
int radius= 32;
float scaleImage= 0.5;
int nItem= 60;
float pMargin= 5;
int limitTime= 70;
float timeWaiting= 8;
bool opTouch= true;
int lastIndex= -1;
Size visibleSize;
CCArray *arrCs;
bool MainGame::init(){
arrCs= CCArray::create();
int xx= pMargin+ radius;
int yy= pMargin+ radius;
int inLabel= 0;
for (int i=0; i<nItem; i++) {
inLabel= i;
if (i>((nItem/2)-1)) {
inLabel= i-(nItem/2);
}
CCString *iconName= CCString::createWithFormat("ricon_%i.png", inLabel);
Sprite *cs= CCSprite::create(iconName->getCString());
cs->setPosition(Point(xx, yy));
cs->setTag(-1);
cs->setScale(scaleImage);
/*****SET VALUE FOR arrCs ******************/
arrCs->addObject(cs);
this->addChild(cs, (1+ rand()%3));
xx= xx+ (radius*2)+ pMargin;
if (xx+ (radius/2)> visibleSize.width) {
xx= radius + pMargin;
yy= yy+(radius*2)+ pMargin;
}
}
}
void MainGame::onTouchesEnded(const std::vector<Touch*>& touches, Event* event){
/******** arrCs has nothing ************/
for (int i=0; i< arrCs->count(); i++) {
}
}