Search code examples
cocos2d-xcocos2d-x-3.0

Cocos2d-x: deprecated class Object


I'm trying to learn from a sample source code (Since the framework is utterly undocumented) that was written for cocos2d-x 3.0alpha, the code is using the deprecated class "Object", I'm trying to port the code to version 3.0 but I'm not sure which class be used instead of Object.

Do you have any idea?

https://github.com/OiteBoys/Earlybird/blob/master/Earlybird/Classes/Number.h

Edit: pretty sure the class I need is Ref


Current issue I'm trying to solve is finding the equivalent of EGLView::getInstance()

Edit II: GLView::create("view"); seems to be it.


Solution

  • Yes, you need Ref. Here are the release notes for Version 3.0. It describes this here. This changes was done since C++ doesn't have and doesn't need a base object. Object was created for that reason originally but now deprecated.

    https://github.com/cocos2d/cocos2d-x/blob/v3/docs/RELEASE_NOTES.md

    For EGLView create a quick sample "Hello World" project using the cocos command-line tool and have a look at AppController.mm, RootViewController.mm and AppDelegate.cpp. These have changed a good deal for version 3.0+.

    Edit: based upon your edit look at: bool AppDelegate::applicationDidFinishLaunching()

    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLView::create("My Game");
        director->setOpenGLView(glview);
    }