我是Cocos2d-x的新手,我不得不在两个CCScenes之间传递一个数组。我这样做了,就这样了:
CCScene* ClassicModeLayer::scene(CCArray *boltArray)
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
ClassicModeLayer *layer = ClassicModeLayer::create();
// add layer as a child to scene
scene->addChild(layer);
layer->mColorArray = CCArray::createWithCapacity(boltArray->count());
layer->mColorArray->addObjectsFromArray(boltArray);
mColorArray->retain();
return scene;
}
但是当我试图以另一种方式访问mColorArray
时:
CCInteger *value = (CCInteger*) mColorArray->objectAtIndex(0);
但它崩溃了。我猜测正在释放内存分配。还有什么我应该做的吗?我试着保留阵列。但那没用。