PhysicsBody isn't moving with its Layer. Cocos2d-x 3.0 RC0

Hello there,

I have an issue can someone please help me solve it? I have made a level which has some scroll features with work by moving the layer, but when I have added physicsBody to my sprites which are in my layer the scroll feature doesn’t work at them. they stay wat the same position. But I want to make them move along with the layer.

I am using Cocos2d-x 3.0 RC0

This is a sample of what I mean.

To create a sprite
Sprite* testBuildS = Sprite::create(“Test.png”);
testBuildS->setTag(1);
testBuildS->setPosition(50,300);
testBuildS->setPhysicsBody(PhysicsBody::createBox(testBuildS->getContentSize()));
this->addChild(testBuildS, 4);

And i move my layer just with
this->setPosition(myPos);

Thanks for reading.

Did you created a gravity world?

Scene* PhysicsLayer::createScene()
{
...
// add following codes
auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);

auto layer = HelloWorld::create();
layer->setPhyWorld(scene->getPhysicsWorld());
...
return scene;
}

please see: [[https://github.com/chukong/cocos-docs/blob/master/manual/framework/native/physics/physics-integration/en.md]]

@jmedeiros
Yes I did I even tried to move the layer in this sample i found on wiki “https://github.com/Yangtb/newPhysics” but the problem still exists the layer is moving but items with physics body stay on the same place.

yeah, setting layer’s position will be not linked to the physics world in 3.0rc.

I asked the developer for help.

They told me that the only way to achieve scroll feature is to move the physical bodies by yourselves in 3.0rc.

Or you can use v2.x version.

@Ryeeeeee

Thanks for your answer.
But is there actually a way to use box2d without using inbuilt cocos2d-x physics system? Beacuse I couldn’t find ENABLE_BOX2D_INTEGRATION anywhere. I have seen some classes check for it but I haven’t found a class which defines it.

Move Complete Scene.