-
Notifications
You must be signed in to change notification settings - Fork 3
Complex Physics Objects
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.
For this tutorial we are going to use the map we created in the previous tutorial.
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.
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.
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.
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.
If you run your game now you will see that polygon shape replace circle shape for santa object.