保留游戏层我多级应用的互联网样本中发现,(有点像割绳子,当你选择的级别)关于在共享实例
存在共同的实例对象,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