Physics Editor + Sprites

Not sure if this is the best place for this question but there isn’t a section for Physics Editor (so feel free to move it to the correct place).
Any way, I’ve been playing around with the trial of PE, but the tutorials on their site don’t show how to implement sprite sheets with PE. My sprite has 4 frames of animation so obviously I would like the physcs data to match the shape of each frame.
Is this easy to implement?

Cheers. [import]uid: 7841 topic_id: 30136 reply_id: 330136[/import]

Do you want the sprite’s physical parts to be solid against the environment or just detect collisions? [import]uid: 63787 topic_id: 30136 reply_id: 128587[/import]

Do you want the sprite’s physical parts to be solid against the environment or just detect collisions? [import]uid: 63787 topic_id: 30136 reply_id: 128587[/import]

I’m also confused about this. I can see that it’s easy enough to draw out the shapes in PE and export out a .lua file containing all of the code, but does anyone know how to use it?

I have a character spritesheet which needs several different collision bodies being applied to it. E.g. when the character is sliding along the floor he has one physics body shape and when he is flying through the air he has another physics body shape. I think this should be easy to do using PE, however, I can’t find any tutorial?

Here’s how I would do it:

  1. Build your physics shapes in PE using the individual images, not the spritesheet.

  2. Code your game to use the sprite sheet. Then you have several options:

2a. Add multiple physics bodies to the same sprite, one for each frame of animation. BUT deactivate all but the current frame - use a “sprite” type event listener to sync the physics bodies to the animation frame. I have never tried this, so I don’t know how it affects density - you probably set the gravity of all the inactive bodies to 0.0 upon initialization and every frame change. I don’t think inactivating bodies nullifies their density though, so you might want to divide the desired total density by the number of bodies you’re using. Let me know how that works out.

2b. Make one body with multiple shapes to cover every frame of animation, but in the PreCollision listener, test event.element1 and/or event.element2 to see which shape is being collided with. If it’s the wrong one for the animation frame you’re playing, (current frame is accessible as a sprite property) then you can set event.contact.isEnabled = false and it will act as if that particular shape on the body never touched the other object.

There are a few other ways to try it, but I would try one of those first.

Sorry that last post by ary109 was actually me. I was using my friend’s computer to post it, and didn’t realize my friend was still logged into Corona forum!

I’m also confused about this. I can see that it’s easy enough to draw out the shapes in PE and export out a .lua file containing all of the code, but does anyone know how to use it?

I have a character spritesheet which needs several different collision bodies being applied to it. E.g. when the character is sliding along the floor he has one physics body shape and when he is flying through the air he has another physics body shape. I think this should be easy to do using PE, however, I can’t find any tutorial?

Here’s how I would do it:

  1. Build your physics shapes in PE using the individual images, not the spritesheet.

  2. Code your game to use the sprite sheet. Then you have several options:

2a. Add multiple physics bodies to the same sprite, one for each frame of animation. BUT deactivate all but the current frame - use a “sprite” type event listener to sync the physics bodies to the animation frame. I have never tried this, so I don’t know how it affects density - you probably set the gravity of all the inactive bodies to 0.0 upon initialization and every frame change. I don’t think inactivating bodies nullifies their density though, so you might want to divide the desired total density by the number of bodies you’re using. Let me know how that works out.

2b. Make one body with multiple shapes to cover every frame of animation, but in the PreCollision listener, test event.element1 and/or event.element2 to see which shape is being collided with. If it’s the wrong one for the animation frame you’re playing, (current frame is accessible as a sprite property) then you can set event.contact.isEnabled = false and it will act as if that particular shape on the body never touched the other object.

There are a few other ways to try it, but I would try one of those first.

Sorry that last post by ary109 was actually me. I was using my friend’s computer to post it, and didn’t realize my friend was still logged into Corona forum!

Did any of the solutions work?

Would be fun to see a small sample if you manged to get it to work :slight_smile:

Did any of the solutions work?

Would be fun to see a small sample if you manged to get it to work :slight_smile:

yes please. normally i would recommend never changing physics bodies shapes on a moving object (they get caught on other bodies), but i am interested in what you came up with.

yes please. normally i would recommend never changing physics bodies shapes on a moving object (they get caught on other bodies), but i am interested in what you came up with.