Cocos2D - 节点vs alloc / init

时间:2011-10-26 06:42:28

标签: ios objective-c cocos2d-iphone

以下两行之间的区别是什么?

1

[CCLayer node]

2

[[CCLayer alloc] init]

2 个答案:

答案 0 :(得分:7)

[CCLayer node]会返回自动释放的对象。

[[CCLayer alloc] init]会返回非自动释放的对象

答案 1 :(得分:5)

詹姆斯说得对,但我只是想补充说OP可以只调查CCNode.m(或者只是在Xcode中按node上下文并选择“跳转到定义”)来查找以下方法实现:

#pragma mark CCNode - Init & cleanup

+(id) node
{
    return [[[self alloc] init] autorelease];
}

因此,[CCLayer node]相当于[[[CCLayer alloc] init] autorelease]

相关问题