Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HelloWorld::init() does not get called when HelloWorld::createWithPhysics() is called. #17093

Closed
Rubonnek opened this issue Jan 1, 2017 · 4 comments

Comments

@Rubonnek
Copy link
Contributor

Rubonnek commented Jan 1, 2017

  • cocos2d-x version: latest git repository as of December 31, 2016
  • devices test on: Linux, Mac
  • developing environments
    • Mac Xcode version: 8.2
    • Linux GCC: 6.2.1

Steps to Reproduce:

  1. Create a new CPP sample project:
cocos new -l cpp inittest
  1. Change line 8 from HelloWorldScene.cpp to:
    return HelloWorld::createWithPhysics();
  1. Compile
#Linux
cocos run -p linux

#Mac
cocos run -p mac
  1. Nothing in the scene will show up. HelloWorld::init() is not getting called.
@Rubonnek Rubonnek changed the title Scene::init() is not called when Scene::createWithPhysics() gets called. HelloWorld::init() does not get called when HelloWorld::createWithPhysics() is called. Jan 1, 2017
@Rubonnek
Copy link
Contributor Author

Rubonnek commented Jan 1, 2017

@Rubonnek
Copy link
Contributor Author

Rubonnek commented Jan 1, 2017

The problem lies in lines 41 through 56 of CCPlatformMacros.h. Doing the changes I stated above to HelloWorldScene.cpp avoids running the create() function created by the CREATE_FUNC macro which also avoids running the HelloWorld::init() method.

Changing line 8 of HelloWorldScene.cpp to the following:

auto scene = HelloWorld::create();
scene->initWithPhysics();
return scene;

fixes this issue temporarily.

The only problem I see with doing this is that Scene::init() and Scene::initWithPhysics() overlap in functionality and incurs in a small unnecessary overhead. There's no need to call both of these functions.

@Rubonnek
Copy link
Contributor Author

Rubonnek commented Jan 1, 2017

Just noticed that the proper way of initiating a scene with physics now is to change line 16 of HelloWorldScene.cpp to the following:

    if ( !Scene::initWithPhysics() )

@Rubonnek Rubonnek closed this as completed Jan 1, 2017
@naklow12
Copy link

Just noticed that the proper way of initiating a scene with physics now is to change line 16 of HelloWorldScene.cpp to the following:

    if ( !Scene::initWithPhysics() )

Omg you solved my problem thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants