简体   繁体   English

cocos2d v3覆盖清除

[英]cocos2d v3 override cleanup

I have been working in cocos2d for a few years now. 我已经在cocos2d中工作了几年。 After making the switch to v3 I really miss being able to override the cleanup function. 切换到v3后,我真的很想念能够覆盖cleanup功能。 In my sprites I would typically perform all my cleaning up in a way similar to this: 在我的子画面中,通常会以类似于以下的方式执行所有清理工作:

-(void)cleanup {
    // Do other cleanup that is not covered by super.


    // Call super cleanup.
    [super cleanup];
}

With v3 it appears that the cleanup function is private to CCNode and cannot be overridden. 在v3中, cleanup功能似乎是CCNode专用的,不能被覆盖。 The main reason for using this approach was that the function would be called automatically with a simple removeFromParent call. 使用这种方法的主要原因是可以通过简单的removeFromParent调用自动调用该函数。

Does anyone have a suggestion how to go about doing something like that in v3 other than writing my destroy function and calling it manually? 除了编写我的destroy函数并手动调用它以外,还有人建议在v3中做什么吗?

Depends on the use case. 取决于用例。

Normally I just call [node removeFromParentAndCleanup:YES] , which is enough for my needs. 通常,我只调用[node removeFromParentAndCleanup:YES]满足我的需要。

If you want direct access to the private cleanup method in a subclass of CCNode you should just import CCNode_Private.h in you header file instead of CCNode.h . 如果要直接访问CCNode子类中的private cleanup方法,则应仅在头文件中导入CCNode_Private.h而不是CCNode.h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM