Physics shape with sprite sheets?

Hi Gurus!

it is now close to 24 hours that i am looking for the answer all over the internet but couldn’t find :frowning:

I have a sprite sheet for my main character and want to create custom shape for it.

Is it even possible? How? can you provide me a sample code please?

Thanks!

You can have one set of physics shapes for the entire spite set.  You cannot have individual shapes for each frame.

There should be plenty of info in the Physics guide:  http://docs.coronalabs.com/guide/physics/physicsBodies/index.html  under polygon shapes and multi-shape bodies.  You can build some pretty accurate shapes from this, but it applies to the whole sprite, not a frame.  This is one of those cases were you should get it generally close.

you mean if i create a sprite set out of my sprite sheet and define the shapes/bodies it will work?

Let me explain it a little bit more in detail…

I am creating a fighting game.

Whenever the player/enemy punches the collision should happen so i can play getting hit animation of the opponent/decrease his health.

It is not important to be a physics collision detection, Unfortunately i couldn’t find per pixel collision detection solution in corona.

AS you can see in the following image, i set the radius of my character but it doesn’t fit the character specially the punches are not detected at all. and as you can see in the image if i increase the radius then the radius would become too big for characters to even come near each other.

As for setting rectangle instead of radius, the character’s standing frame is smaller in width then the punch frame. And other problem is that i change the scale of my character and the physics body size won’t change.

collision.jpg

The only solution is the custom shapes for my sprite sheet. but i can’t understand how it works and even if it is possible to create shapes for sprite sheets?

guy.jpg

My whole game is pending because of this annoying problem.

I am from 3d community and it is my first time with 2d game development. In 3d environment collision detection is not a problem at all, it is a peace of cake actually. I didn’t know it would be such a big problem in 2d  :0

My request from corona community is to please help me to overcome this annoying obstacle from completing my game.

Thanks in advance! 

Hi @coolromin,

If I understand your request, you want to make the physics collision shape “precisely match” the frame of the animation, is that correct? This is possible, but it will take a bit more effort. At a high-level overview, you’d need to create a complex shape set that encompasses all of the “locations” of the arms/legs, plus (of course) the body and head. This wouldn’t necessarily need to be ultra-precise, but enough so that it would appear logical to the player in real-time gameplay. With those shapes established, you can then selectively turn them on or off using physics pre-collision and detection of which shape index you want to either acknowledge or ignore.

Here’s a couple tutorials on this method:

http://www.coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/

http://www.coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

You may also want to explore Spine. I haven’t used this personally, but it’s a popular skeletal animation product compatible with Corona:

http://esotericsoftware.com/

Hope this helps somewhat,

Brent Sorrentino

^No that is not what i want!

What you are talking is about single frame image/sprite sheets. for that there are tools like PhysicsEditor which does it in few clicks.

I have a multi frame sprite sheet as you can see in the picture above. How to make it work with that?

Nobody knows :open_mouth:

Do you really need physics collisions? Bounding box collision detection would be a lot easier if you have no other need for physics…

Thanks alot for the reply!

I don’t need a physics. Any thing will work for me as long as it is not using circles and squars for collision detection.

I need the real shape of my character for collision detection because my character will be punching and kicking thus each frame is different in width and height so the static boxes and circles will not work…

Anyway what is Bounding box collision detection?

You can have one set of physics shapes for the entire spite set.  You cannot have individual shapes for each frame.

There should be plenty of info in the Physics guide:  http://docs.coronalabs.com/guide/physics/physicsBodies/index.html  under polygon shapes and multi-shape bodies.  You can build some pretty accurate shapes from this, but it applies to the whole sprite, not a frame.  This is one of those cases were you should get it generally close.

you mean if i create a sprite set out of my sprite sheet and define the shapes/bodies it will work?

Let me explain it a little bit more in detail…

I am creating a fighting game.

Whenever the player/enemy punches the collision should happen so i can play getting hit animation of the opponent/decrease his health.

It is not important to be a physics collision detection, Unfortunately i couldn’t find per pixel collision detection solution in corona.

AS you can see in the following image, i set the radius of my character but it doesn’t fit the character specially the punches are not detected at all. and as you can see in the image if i increase the radius then the radius would become too big for characters to even come near each other.

As for setting rectangle instead of radius, the character’s standing frame is smaller in width then the punch frame. And other problem is that i change the scale of my character and the physics body size won’t change.

collision.jpg

The only solution is the custom shapes for my sprite sheet. but i can’t understand how it works and even if it is possible to create shapes for sprite sheets?

guy.jpg

My whole game is pending because of this annoying problem.

I am from 3d community and it is my first time with 2d game development. In 3d environment collision detection is not a problem at all, it is a peace of cake actually. I didn’t know it would be such a big problem in 2d  :0

My request from corona community is to please help me to overcome this annoying obstacle from completing my game.

Thanks in advance! 

Hi @coolromin,

If I understand your request, you want to make the physics collision shape “precisely match” the frame of the animation, is that correct? This is possible, but it will take a bit more effort. At a high-level overview, you’d need to create a complex shape set that encompasses all of the “locations” of the arms/legs, plus (of course) the body and head. This wouldn’t necessarily need to be ultra-precise, but enough so that it would appear logical to the player in real-time gameplay. With those shapes established, you can then selectively turn them on or off using physics pre-collision and detection of which shape index you want to either acknowledge or ignore.

Here’s a couple tutorials on this method:

http://www.coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/

http://www.coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

You may also want to explore Spine. I haven’t used this personally, but it’s a popular skeletal animation product compatible with Corona:

http://esotericsoftware.com/

Hope this helps somewhat,

Brent Sorrentino

^No that is not what i want!

What you are talking is about single frame image/sprite sheets. for that there are tools like PhysicsEditor which does it in few clicks.

I have a multi frame sprite sheet as you can see in the picture above. How to make it work with that?

Nobody knows :open_mouth:

Do you really need physics collisions? Bounding box collision detection would be a lot easier if you have no other need for physics…

Thanks alot for the reply!

I don’t need a physics. Any thing will work for me as long as it is not using circles and squars for collision detection.

I need the real shape of my character for collision detection because my character will be punching and kicking thus each frame is different in width and height so the static boxes and circles will not work…

Anyway what is Bounding box collision detection?

I also have the same problem. İ don’t want square or circle collision. İ would like set diffirrent shape for each frame. Because my char have to has got serparate collion point on each frame. There is diffirent png part on each frame. Totally we need collison without transparrency parts of png how can we hanle it.

I also have the same problem. İ don’t want square or circle collision. İ would like set diffirrent shape for each frame. Because my char have to has got serparate collion point on each frame. There is diffirent png part on each frame. Totally we need collison without transparrency parts of png how can we hanle it.