私はCocos2dのプロジェクトでここで苦しんでいます。私は自分の「誤解」の核心を切り離す小さなプロジェクトを作成しました。
以下は、2つの別々のシーンを作成し、最初の子を再利用するふりをする非常に単純なコードです。ARCを使用するプロジェクトでcocos2dv2を使用しています。
CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello ARC World" fontName:@"Marker Felt" fontSize:64];
CCScene *scene1 = [HelloWorldLayer scene];
CCScene *scene2 = [HelloWorldLayer2 scene];
[director_ pushScene: scene1];
// I add my label to the main layer of my scene1.
[[scene1 getChildByTag:1] addChild:label];
//I reset my own scene1 pointer to make sure only the director points to it.
//scene1 = nil;
// I replace the scene, and hope that the old scene1 will be killed by cocos
[director_ replaceScene: scene2];
// When I want to reuse my "label" object, I get the "child already added..." exception
[[scene2 getChildByTag:2] addChild:label];
なぜこれが間違っているのですか?replaceSceneが私のためにすべての仕事をすることになっているので、RemoveAllChildrenなどをいじってはいけないことを読みました。ここで何か根本的に間違っていると思いますか?異なるシーン間でのオブジェクトの再利用は固く禁じられていますか?