This code works fine:
cocos2d::CCScene* Box2DTestLayer::scene() {
CCScene scene = CCScene::create;
// ‘layer’ is an autorelease object
CCLayerlayer = new Box2DTestLayer();
// add layer as a child to scene
scene~~>addChild;
layer~~>release();
return scene;
}
If layer~~>release called before scene~~>addChild(layer) as following, the layer just could not catch any touch events:
cocos2d::CCScene* Box2DTestLayer::scene() {
CCScene scene = CCScene::create;
// ‘layer’ is an autorelease object
CCLayerlayer = new Box2DTestLayer()::create();
// add layer as a child to scene
scene~~>addChild;
layer~~>release();
return scene;
}
/////////////////////////////////////////////////////////////////////////////////
I run the Box2dTest in this way:
// create a scene. it’s an autorelease object
CCScene* scene = Box2DTestLayer::scene();
pDirector->runWithScene(scene);