Cocos2d-x 3.0rc Physics

Cocos2d-x 3.0rc Physics
0.0 0


I have just started physics game with cocos2d-x 3.0rc. I am having problem with function
m_world->setGravity(const Vect &gravity);
How can pass the vect to this function. I have tried different methods but all giving me errors. I am using xCode 5.0.2.


Vect is a typedef of Point - at least it was in the Betas.
Point(float x, float y) and Vect(float x, float y) is therefor equal.

In turn, this means you can du this:
m_world->setGravity(Vect(0, -9.8f));
-9.8f is merely an approximation of earths gravity.

To clearify the syntax:
Vect gravity(0, -9.8f);

Btw, Vect is not std::vector<> if that’s what made the confusion :slight_smile:

Hope this helps you.


Hi Thanks for reply. I have already tested these syntax.
xcode error mode takes me to this link
if (!_bodies.empty())

I have added the bodies also to the world. If I not setGravity, it works fine.
I just want to set the gravity (0,0).


Oh my bad.
You have to set the gravity before setting the PhysicsWorld of the scene.
Here is the code for the future help .
`Scene* GamePlayScene::createScene(){

auto scene = Scene::createWithPhysics();


auto layer = GamePlayScene::create();


return scene;