为了弄清楚选择了什么级别,我想将选定的按钮信息分享给被替换的场景..我该怎么做?
CCLabelBMFont *label = [CCLabelBMFont labelWithString:@"Lavel_2" fntFile:@"font.fnt"];
CCMenuItemLabel *titem = [CCMenuItemLabel itemWithLabel:label target:self selector:@selector(sceneLoader:)];
CCMenu *menu = [CCMenu menuWithItems: titem, nil];
menu.position = ccp(screenSize.width/2, screenSize.height/2);
[self addChild:menu];
- (void)sceneLoader:(id)sender {
[[CCDirector sharedDirector] replaceScene: [GameLayer scene]];
}
答案 0 :(得分:0)
标记您的商品,然后将代码设置为GameLayer
像这样......titem.tag = 777;
...
- (void)sceneLoader:(CCNode)sender {
GameLayer *gameLayer = [GameLayer scene];
gameLayer.gameLevel = sender.tag;
[[CCDirector sharedDirector] replaceScene: gameLayer];
}
答案 1 :(得分:0)
为场景创建单独的初始值设定项。或者至少有一个带枚举:
[[GameLayer alloc] initWithButton:kSceneLoaderButton];
答案 2 :(得分:-1)
对于那种操作,我使用单身人士
file.h
@interface YourClassName : NSObject
+ (id)sharedInstance;
@property (nonatomic,retain) NSString * selectedLevel;
file.m
@implementation YourClassName
@synthesize selectedLevel;
+ (id)sharedInstance {
static YourClassName *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (id)init
{
self = [super init];
if (self) {
selectedLevel = [NSString string];
}
return self;
}
如果您想使用它,只需致电[[YourClassName sharedInstance] selectedLevel
或设置[[YourClassName] setSelectedLevel]
希望能帮到你。