Scene* GameScene::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setDebugDrawMask( PhysicsWorld::DEBUGDRAW_ALL );
// 'layer' is an autorelease object
auto layer = GameScene::create();
layer->setPhysicsWorld( scene->getPhysicsWorld() );
scene->addChild(layer);
return scene
}
but the new cocos2d-x code doesnt have layer in the createScene method ? would this be the right way to implement the equivalent code to the top ? do i need to make a layer object to add setPhsyicsWorld to like above ?
Scene* HelloWorld::createScene()
{
auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
return scene;
}
I noticed in alot of other tutorials and books iâve been reading they add the layer code the createScene method ?
also what is the difference between createWithPhysics and initWithPhysics ??
and this will replace the need for the setPhsyicsWorld method? , and âauto scene = Scene::createWithPhysics();â? also if thats all I change to a newly created cocos2d-x project to add physicsWorld what object do I call ->setDebugDrawMask( PhysicsWorld::DEBUGDRAW_ALL ) on ??
ok so all these books I have are outdated then from 2015, they all say I need to add layer inside the create scene method like I put in the above code, this is no longer necessary ??
do you know which version of cocos2d-x initWithPyhsics was introduced in ? im wondering why they didnât use it in this book, and classes derived from layer in this book to instead of scene
I did not know how to add physics world in the new cocos2d-x code because all the books and old tutorials im following go by this
Scene* GameScene::createScene() {
// âsceneâ is an autorelease object
auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setDebugDrawMask( PhysicsWorld::DEBUGDRAW_ALL );
// âlayerâ is an autorelease object auto layer = GameScene::create();
layer->setPhysicsWorld( scene->getPhysicsWorld() );
scene->addChild(layer);
return scene }
and in the new cocos2d-x projects they dont have any mention of the âlayerâ object in createScene method so I just wanted to know how to implement physics in cocos2d-x 3.17 pretty much
there is no docs about calling âsetDebugDrawMaskâ ??
also one question if anybody knows the answer im trying to figure out why on the tutorials im following they call both of these in HelloWorld::createScene() method auto scene = Scene::create(); auto layer = HelloWorld::create();
and now in new cocos2d-x Projects they only call
return HelloWorld::create();
and they scene::create() isnt being called ?
Oh ok that makes sense itâs a scene because itâs derived from scene , so they only use to call it before because HelloWorld use to be derived from layer ?