@implementation demoScene{
-(void) initializeScene {
moon *_moon=[[moon alloc]init];
}
-(void) updateBeforeTransform: (CC3NodeUpdatingVisitor*) visitor {
deltaTime =deltaTime+visitor.deltaTime;
NSLog(@"delta time=%0.12f",deltaTime);
[_moon print:deltaTime/100000];
}
@end这是我的问题。
我希望在initializeScene方法中从moon类中创建一个对象,并希望在updateBeforeTransform方法中向该对象发送消息。
当我键入这样的代码时,我无法向_moon对象发送消息,也无法获得“未使用变量”警告消息.。
我知道对象超出了范围,但是如果我需要从updateBeforeTransform方法发送消息的话。updateBeforeTransform方法在一秒钟内被调用了60次。所以我不想在一秒钟内创建60次对象。
如有任何建议,将不胜感激。
发布于 2012-12-21 00:32:17
您需要一个实例变量,而不是在initializeScene方法中创建一个新变量:
@implementation demoScene {
moon *_moon; // You may already have this in the .h file - just have it in 1 place.
}
- (void)initializeScene {
_moon = [[moon alloc] init]; // assign to ivar
}
- (void)updateBeforeTransform:(CC3NodeUpdatingVisitor*) visitor {
deltaTime = deltaTime + visitor.deltaTime;
NSLog(@"delta time=%0.12f", deltaTime);
[_moon print:deltaTime / 100000];
}
@end侧注-类名应以大写字母开头。变量和方法名以小写字母开头。
https://stackoverflow.com/questions/13982662
复制相似问题