Skip to content

Complex Physics Objects

ldurniat edited this page Jan 9, 2018 · 2 revisions

In one of previous tutorial we saw how easy it was to create simple physics objects from tiles and objects, we will now see how easy it is to create more interesting shapes.

Step 1: Getting your map

For this tutorial we are going to use the map we created in the previous tutorial.

Step 2: Creating a circular object

Creating a circular body couldn’t be simpler and can be done on both tiles and objects, this example will show you how to create one on a tile however it is the same process for an object.

First set up your tile properties as before, remembering to include the hasBody property. Then simply add a radius property as shown below.

Radius Property

You can of course still set all the other physics properties as before I am just showing this now to keep it nice and simple.

You may also wish to set the drawMode to hybrid in map options just so that you can see your new circular body.

Circle In Game

Step 3: Creating a polygon collision shape

Circles are great for some things but what is really great is custom shapes, these can help make terrain creation so much simpler. Rather than using trial and error with rotation you can just draw out your terrain like a dot-to-dot picture.

In order to do this you will use the Tile Collision Editor tool. From tool bar choose polygon shape and start adding vertices by left click on tile. To stop adding more vertices right click somewhere on background. The resulting shape must be convex-only. This is limiation of Corona itself. Berry support only two shapes: polygon and rectangle.

Multiple Shapes

I have also set the bodyType to static in the Object Properties to make sure it stays where we want it and have added some more tiles above it to see them fall and slide on our terrain.

Step 4: Run your game

If you run your game now you will see that polygon shape replace circle shape for santa object.

Complete