首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“未用变量”

“未用变量”
EN

Stack Overflow用户
提问于 2012-12-21 00:29:13
回答 1查看 284关注 0票数 1
代码语言:javascript
复制
@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次对象。

如有任何建议,将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-21 00:32:17

您需要一个实例变量,而不是在initializeScene方法中创建一个新变量:

代码语言:javascript
复制
@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

侧注-类名应以大写字母开头。变量和方法名以小写字母开头。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13982662

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档