Making Physics Objects
In this tutorial you will learn how to:
- add physics to your projects
- randomize objects positioning
- setting physics properties
- work with Physics Editor, from Code and Web Inc.
You can download the project files here. My thanks to Matthew Peacock at Anonymous Creative Group for providing the demo direction and Photoshop file!
.psd is 768 x 1024. You can create a new project with iPad Mini.
You find the following layers in falling.psd has
- sb1 .. until sb13 balls
Creating a virtual wall
Setting the environment
- Create Virtual walls around the screen
Hybrid is a debug mode to check the body shape, in the final build, please get it back to Normal
Select the all sbXX ball layers and click to open the layer properties in order to set the same properties to the layers at once
Layer Properties Window,
- X between 0 and 1024
- Y between -300 and 0
Render as sb1
Physics Body - Dynamic
Keeping the multiple sections on the ball layers, click Set body properties from Physics
The following properties will be applied to all the balls
- Shape Circle
Physics Body - Staic
Select logo layer and make it Static body and set the shape from poly.lua
Kinematic body is not affected with gravity, so it is never falling but if another object hits it , it follows the law of physics. If isSensor is true, it ignores collisions.
Integration with Physics Editor
Physics Editor is a 3rd party tool to make the polygon shape for image. It outputs the coordinates of polygon shape to lua file. As we made Hybrid environment, you see the green overlay on the logo, it tells where the physics shape exists. Each ball’s shape is circle and it is overlay in orange because dynamic object. The logo is static so it is green.
Please check how to use Physics Editor from CodeAndWeb
You can drag the logo image from build4/assets/images/p1/logo.png to Physics Editor and the identifier for “logo” image should be “logo”.