保留遊戲層我多級應用的互聯網樣本中發現,(有點像割繩子,當你選擇的級別)關於在共享實例
存在共同的實例對象,NSObject的是遊戲的大腦,其中的邏輯遊戲存儲
@interface GameData : NSObject {
ObjLevelInfo *levelInfoArray[MAX_LEVEL_NUMBER]; // array to store level info
int _curLevelIndex; // current playing level number, local
int _curScore; // current score, local
CCLayer *_curGameLayer; // link to current Game Layer, local
}
@property (nonatomic) int curLevelIndex; // current playing level number
@property (nonatomic) int curScore; // current score
@property (nonatomic, retain) CCLayer *curGameLayer; // link to current Game Layer
curGameLayer用於存儲當前運行層。
還有幾款遊戲場景的CCLayer類。 在這些類的init方法,我發現
-(id) init
{
if((self=[super init])) {
//make sure you call this to correctly link GameData with this game layer
[[GameData sharedInstance] setCurGameLayer:self];
...
這將每一次新的場景將加載發生,我不知道這可能是泄漏的來源?當遊戲數據保留它時新場景會加載時,場景是否會從內存中移除?
更新:
我已經找到很好的教程在這裏http://www.learn-cocos2d.com/files/cocos2d-essential-reference-sample/Strategies_for_Accessing_Other_Nodes.html#2687105_StrategiesforAccessingOtherNodes-AccessingtheCurrentlyRunningSceneviaDirector.So如果我刪除@property (nonatomic, retain) CCLayer *curGameLayer;
財產,也[[GameData sharedInstance] setCurGameLayer:self];
這個鏈接,並在遊戲數據使用
CCScene* runningScene = [CCDirector sharedDirector].runningScene;
MyScene* gameScene;
insted的,並使用像(MyProgressBar *)[gameScene getChildByTag:progressBarTag];
東西訪問正在運行場景節點,它仍然是一個問題?
非常感謝您的回答。這是非常糟糕的,不幸的是我在這方面做了非常大的工作:(有沒有辦法添加一些代碼,檢查和更正來正確運行這個方案不正確的方案?ARC在我的項目中啓用。 – Grixol