Cocos2D - 节点与分配/初始化
下面两行有什么区别?
1.
[CCLayer node]
2.
[[CCLayer alloc] init]
What's the difference between the following two lines?
1.
[CCLayer node]
2.
[[CCLayer alloc] init]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
[CCLayer 节点]
返回一个自动释放对象。[[CCLayer alloc] init]
返回一个非自动释放对象[CCLayer node]
returns an autoreleased object.[[CCLayer alloc] init]
returns an non-autoreleased objectJames 说得对,但我只是想补充一点,OP 可以查看 CCNode.m(或者简单地在 Xcode 中上下文单击
node
并选择“跳转到定义”) ”)找到以下方法实现:因此,
[CCLayer node]
等价于[[[CCLayer alloc] init] autorelease]
。James got it right, but I just want to add that OP could just look into
CCNode.m
(or simply context-clicking onnode
in Xcode and choose "Jump to Definition") to find the following method implementation:So,
[CCLayer node]
is equivalent to[[[CCLayer alloc] init] autorelease]
.