Starting in Daily Build #2154, we’ve added the ability to trace the outline of non-transparent assets in both an image or frames from an image sheet. These outlines can then be used for drawing a polygon or generating physics bodies (no need to determine the body shapes using a 3rd-party physics tracing application). This feature is accomplished using the new graphics.newOutline() API, available to Pro and Enterprise users.

Basic Images

Let’s explore the usage of graphics.newOutline() with a basic image:

star
star_sample

Using this image, you can extract the outline like so:

The first parameter defines the coarsenessInTexels which may be adjusted to increase or decrease the “resolution” of the traced outline. Higher values produce lower resolution outlines, while lower values produce larger outlines that may hurt performance. It’s up to you how detailed you want the outlines to be.

Then you can use the outline with the physics engine:

To see this in action, please see the Png2Box2D sample located in the application folder of the associated Daily Build:

CoronaSDK → SampleCode → Physics → Png2Box2D

Image Sheet Frames

This feature is also compatible with image sheets. For example:

alphabet

letter_sampleUsing this image sheet, you can extract the outline of a particular frame like so:

In Summary

While truly “customized” multi-element physics bodies may still need to be obtained from 3rd-party tools like PhysicsEditor, the new graphics.newOutline() function provides a convenience method for obtaining the outline of images or image sheet frames for use with the physics engine. Enjoy!

Excerpt from – 

Tutorial: Create Physics Bodies from Texture Assets