I’ve seen a few issues using version 3.16 - I used to use this code to create a physics seen now it seems to duplicate layers & sprites and not work with follow action.
auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setDebugDrawMask( PhysicsWorld::DEBUGDRAW_ALL );
// 'layer' is an autorelease object
auto layer = cchMain::create();
layer->SetPhysicsWorld( scene->getPhysicsWorld() );
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
I found this post (Cocos2dx - Chipmunk c++) and used code added debug drawall to follow sprite and now when it hits a certain point the debug mask now goes off screen???
I dont think I’ve ever had any issues using previous versions but this totally flakey… thinking about going down a version or two. Anyone else with similar experiences?
Thanks for looking into it slackmoehrle. I have just tested this on version 3.14 exactly same config with IOS 10.3.1 everything is working fine follow action with physics & debug draw??
Has version 3.16 gone through a rehaul… the only differences I am seeing is the way physics scenes are getting set up and possible layering issues.
Version 3.14
HelloWorld.h
class HelloWorld : public cocos2d::Layer
{
public:
static cocos2d::Scene* createScene();
//virtual void onEnter();
virtual bool init();
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
private:
Sprite *cocoTooth;
// Setting up PhysicsWorld
cocos2d::PhysicsWorld *sceneWorld;
void SetPhysicsWorld( cocos2d::PhysicsWorld *world ) { sceneWorld = world; };
// Physics contact
}
HelloWorld.cpp
Scene* HelloWorld::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
// 'layer' is an autorelease object
auto layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
}
Version 3.16 -
HelloWorld.h
class HellloWorld : public cocos2d::Scene
{
public:
static cocos2d::Scene* createScene();
// virtual void onEnter();
virtual bool init();
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
private:
Sprite *cocoTooth;
// Setting up PhysicsWorld
cocos2d::PhysicsWorld *sceneWorld;
void SetPhysicsWorld( cocos2d::PhysicsWorld *world ) { sceneWorld = world; };
}
HelloWorld.cpp
Scene* HelloWorld::createScene()
{
auto scene = Scene::createWithPhysics();
auto layer = HelloWorld::create();
scene->addChild(layer);
scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
return scene;
}
// Print useful error message instead of segfaulting when files are not there.
static void problemLoading(const char* filename)
{
printf("Error while loading: %s\n", filename);
printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Scene::initWithPhysics() )
{
return false;
}
}
Maybe I am not using scene right in the headers for physics or scene creation. Is there any new documentation for 3.16… for the way it works and this new fundamental change?
Just need to leave a comment on an issue I saw but this post fixed. When transitioning scenes to a scene with physics, it would not load the scene. Just a black screen. I was doing this:
FrogScene inherited from cocos2d::Scene. Thanks to @chint I see you got to do it this way to make it load properly:
cocos2d::Scene *FrogScene::createScene() {
auto scene = Scene::createWithPhysics();
auto layer = FrogScene::create();
scene->addChild(layer);
return scene;
}
Did I just miss the documentation on this or should this be added?
Thanks guys!
cocos2d-x 3.16 is totally messed up;/ we don’t have time to investigate issues so we not using it anymore - but it is just crashing on Android and IOS. Someone should do something about it.