この保持サイクルを理解できません。誰かがそれを見つけるのを手伝ってくれれば幸いです。
へRootController
の強力な参照を保持するオブジェクトがありますRootView
。
@interface RootController : CCNode <TouchDelegate, GUIDelegate, ModelViewDelgate>
...
@property (nonatomic, weak) CCDirector *director;
@property (nonatomic) RootView *view;
...
@end
@implementation
- (id)init {
...
_view = [[RootView alloc] initWithController:self];
[self addChild:_view];
...
}
return self;
}
@end
コントローラへの参照と を保持するRootView
オブジェクトがあり、プロトコルactiveGame
に準拠していること以外の詳細を知る必要なく、ゲームの種類を切り替えることができます。<TouchDelegate>
@interface RootView : CCScene
...
@property (nonatomic, assign) RootController *controller;
@property (nonatomic) GameplayLayer <ModelViewDelgate> *activeGame;
...
@end
@implementation RootView
- (id)init {
...
self.activeGame = [[GameplayLayer alloc] initWithDelegate:_controller root:self type:type];
[self addChild:self.activeGame];
...
}
return self;
}
@end
最後に、必要に応じて RootView によって呼び出される GameplayLayer を用意し、RootViewによって割り当てを解除する必要があります。
@interface GameplayLayer : CCLayer <ModelViewDelgate, Updatable>
...
@property (nonatomic, assign) RootView *rootView;
@property (nonatomic, assign) RootController <TouchDelegate> *touchDelegate;
...
@end
コントローラー クラスがゲームのクリーンアップ (通常はゲームのハード リセット) を決定すると、私のプロジェクトの他のすべてのクラスは、dealloc メソッドを受け取ることのないこの GameplayLayer を除いて、文字通り割り当てが解除されます。私は何が欠けていますか?ゲームを「再起動」する方法は次のとおりです...
[[CCDirector sharedDirector] replaceScene:[RootController node]];