Sensor shapes in Corona are amazing!

Last night I discovered sensors in Corona. If you've not found out about these yet, and you're getting into game development with Corona, you need to see what these things can do.

Start on this page:

http://developer.anscamobile.com/content/game-edition-physics-bodies

Look for:

Sensors

and...

Polygon bodies

If you're new to Corona, like me, then Sensors let you specify a custom hit detection shape for an actor on stage. If you have an animated sprite that's anything other than a chunky box shaped character, you'll likely want to set a sensor for the body that's smaller than the default rectangular shape that will be applied.

In flash, I used to make sensors for each actor movieClip using a rectangle from separate objects. They were used to detect hits with ledges, platforms and when a character hit another one. With GameSalad, you create a rectangle object and constrain it's X and Y to the actor. Corona makes it much easier to do.

1
2
3
local zombie = display.newImage("zombie.png");
sensorShape = {-10,-10,10,-10,10,10,-10,10};
physics.addBody( zombie, { isSensor = true, shape = sensorShape} )

@tom,
you can also have an invisible rectangle at the same position as the image that will act as the sensor providing you collision events.

cheers,

?:)

views:1368 update:2011/9/30 9:15:39
corona forums © 2003-2011