如果我这样做,我可以从另一个类中获得变量:从其他类中取回变量不工作
--------------------- ------- HelloWorldLayer.h -------------------------------
@interface HelloWorldLayer : CCLayer
{
...
BOOL win;
...
}
@property (nonatomic,readwrite) BOOL win;
- -------------------------- HelloWorldLayer.m --------------------- ----------
@synthesize win;
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (...){
//do something with with variable win ----> IN <---- if statement
win = YES;
}
//win is changed only in if statement
}
---------------------------- LevelDone.m - -----------------------------
-(void)nextLevel:(id)sender{
NSLog(@"next level");
HelloWorldLayer *obj = [[HelloWorldLayer alloc]init];
if (obj.win==YES){
NSLog(@"win = YES");
}else {
NSLog(@"win = NO");
}
win = NO;
[[CCDirector sharedDirector] popScene];
}
我可以先获取和设置变量win
这里,让其他类现在有NO
分配赢变量或者是在if语句不是全局处理赢的分配?
,如果我在init
方法分配变量NO
,并改变它的功能,它只会采取了在init
方法被赋予的价值......究竟为什么会这样?
谢谢。我以前曾经想过,但是我(被错误地)告知我实际上可以访问它们。 – 2011-12-16 17:42:04