diff --git a/cocos/2d/CCScene.cpp b/cocos/2d/CCScene.cpp index 363db8d19f21..4df4f5b2228f 100644 --- a/cocos/2d/CCScene.cpp +++ b/cocos/2d/CCScene.cpp @@ -50,28 +50,16 @@ THE SOFTWARE. NS_CC_BEGIN Scene::Scene() +: _defaultCamera(Camera::create()) +, _event(Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_PROJECTION_CHANGED, std::bind(&Scene::onProjectionChanged, this, std::placeholders::_1))) { -#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION - _physics3DWorld = nullptr; - _physics3dDebugCamera = nullptr; -#endif -#if CC_USE_NAVMESH - _navMesh = nullptr; - _navMeshDebugCamera = nullptr; -#endif -#if CC_USE_PHYSICS - _physicsWorld = nullptr; -#endif _ignoreAnchorPointForPosition = true; setAnchorPoint(Vec2(0.5f, 0.5f)); - _cameraOrderDirty = true; - //create default camera - _defaultCamera = Camera::create(); + addChild(_defaultCamera); - _event = Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_PROJECTION_CHANGED, std::bind(&Scene::onProjectionChanged, this, std::placeholders::_1)); _event->retain(); Camera::_visitingCamera = nullptr; diff --git a/cocos/2d/CCScene.h b/cocos/2d/CCScene.h index be24d4e9c99f..c2fbc16f335c 100644 --- a/cocos/2d/CCScene.h +++ b/cocos/2d/CCScene.h @@ -137,9 +137,9 @@ class CC_DLL Scene : public Node friend class Renderer; std::vector _cameras; //weak ref to Camera - Camera* _defaultCamera; //weak ref, default camera created by scene, _cameras[0], Caution that the default camera can not be added to _cameras before onEnter is called - bool _cameraOrderDirty; // order is dirty, need sort - EventListenerCustom* _event; + Camera* _defaultCamera = nullptr; //weak ref, default camera created by scene, _cameras[0], Caution that the default camera can not be added to _cameras before onEnter is called + bool _cameraOrderDirty = true; // order is dirty, need sort + EventListenerCustom* _event = nullptr; std::vector _lights; @@ -183,12 +183,12 @@ class CC_DLL Scene : public Node void addChildToPhysicsWorld(Node* child); #if CC_USE_PHYSICS - PhysicsWorld* _physicsWorld; + PhysicsWorld* _physicsWorld = nullptr; #endif #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION - Physics3DWorld* _physics3DWorld; - Camera* _physics3dDebugCamera; // + Physics3DWorld* _physics3DWorld = nullptr; + Camera* _physics3dDebugCamera = nullptr; #endif #endif // (CC_USE_PHYSICS || CC_USE_3D_PHYSICS) @@ -204,8 +204,8 @@ class CC_DLL Scene : public Node void setNavMeshDebugCamera(Camera *camera); protected: - NavMesh* _navMesh; - Camera * _navMeshDebugCamera; + NavMesh* _navMesh = nullptr; + Camera * _navMeshDebugCamera = nullptr; #endif #if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION) || CC_USE_NAVMESH)