【发布时间】:2013-03-14 22:03:37
【问题描述】:
我有一个关于在继承自 CCNode 的 Player 类中创建自定义初始化方法的问题。不确定我是否需要改用其他路线并创建类方法:
+ (id) addSprite: (CCSprite*) sprite andSpriteBatchNode: (CCSpriteBatchNode*) spriteBatch;
更多类方法....
在Player类中,我有一个指定的init方法,以及一些方便的init方法。- (id) init;- (id) initWithSpriteBatchNode: (CCSpriteBatchNode*) spriteBatch;- (id) initWithSprite: (CCSprite*) sprite andSpriteBatchNode: (CCSpriteBatchNode*) spriteBatch; //指定的init方法
当我在我的 Level 类中实例化这个类时,我无法直接调用我的任何自定义 init 方法。我要做的是:
Player *player = [Player node];[player initWithSprite: sprite andSpriteBatchNode: spriteBatch;]; //不确定这是否正确还是会泄漏内存
我认为任何一个都应该工作,因为它们只是在实例级别上做同样的事情,其他方法在名称上。
请指教。
【问题讨论】:
标签: objective-c cocos2d-iphone ccnode