O'Reilly logo

Building Android Games with Cocos2d-x by Raydelto Hernandez

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling gravity

Now that we have successfully used the built-in physics engine to detect the collision, let us play a little bit with gravity. Go to the createScene method and modify the parameters that we have sent to the constructor. In our game, we have used the (0,0) value, since we did not want our world to have any gravity force that moves our bodies on either the x or the y axis.

Now, give it a try, change the values to positive or negative. When we use a negative value on the x axis, it will attract the body toward the left, and when we use the negative value on the y axis, it will attract the body toward the bottom.

Note

Changing these values and understanding the physics added to our game might give you some ideas for your next games. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required