Page 1 of 2

Physics tutorial question

Posted: Mon Nov 15, 2010 11:25 pm
by Czrlos
Hi everyone, in the physics tutorial http://love2d.org/wiki/Tutorial:Physics,I want to know If it's possible to have an image instead of the ball shape as a physic's object, and if it is can you indicate me how?
Sorry to bother you people with such simple question but I'm new to programming.

Re: Physics tutorial question

Posted: Mon Nov 15, 2010 11:30 pm
by zac352
All I can think of for something like that is cutting the image into small rectangles connected with joints. Or maybe a function to edge detect on the image. :|

Re: Physics tutorial question

Posted: Mon Nov 15, 2010 11:37 pm
by ninwa
Zac is right. I don't think there's anyway to assign an image to a shape, you have to keep track of them yourself.

Re: Physics tutorial question

Posted: Mon Nov 15, 2010 11:38 pm
by vrld
The shape is only used internally for collisions. You can have a circle shape but in fact draw an image instead of a circle. Instead of using

Code: Select all

love.graphics.circle("fill", bodies[1]:getX(), bodies[1]:getY(), shapes[1]:getRadius(), 20)
You could draw the image with width and height of 2 times the radius of the shape:

Code: Select all

love.graphics.draw(theImage, bodies[1]:getX()-shapes[1]:getRadius(), bodies[1]:getY()-shapes[1]:getRadius())
You should only do this if the image you are using is showing something that is approximately a circle though, otherwise you should use a rectangle shape.

Anyway, as the hammer suggests, you should probably not touch the physics module for a while. At least until you are comfortable with the basic concepts of both LÖVE and Lua.

Re: Physics tutorial question

Posted: Mon Nov 15, 2010 11:46 pm
by zac352
vrld wrote:Anyway, as the hammer suggests, you should probably not touch the physics module for a while. At least until you are comfortable with the basic concepts of both LÖVE and Lua.
Finally, someone else points out the big fat warning happily camping on the physics module documentation. :P

Re: Physics tutorial question

Posted: Tue Nov 16, 2010 6:01 pm
by tentus
zac352 wrote:
vrld wrote:Anyway, as the hammer suggests, you should probably not touch the physics module for a while. At least until you are comfortable with the basic concepts of both LÖVE and Lua.
Finally, someone else points out the big fat warning happily camping on the physics module documentation. :P
The problem is, there is not an alternative readily offered up. When I started my game, it was much easier to start wildly abusing the physics than it was to figure out and write my own collision system. I know I'm not the only one doing this either. If you want to berate newcomers for using physics, make sure there is an obvious alternative that is clearly easier for them.

Re: Physics tutorial question

Posted: Tue Nov 16, 2010 8:12 pm
by zac352
I'll make a lightweight physics library. Eventually. :P

Re: Physics tutorial question

Posted: Tue Nov 16, 2010 8:16 pm
by Robin
tentus wrote:The problem is, there is not an alternative readily offered up. When I started my game, it was much easier to start wildly abusing the physics than it was to figure out and write my own collision system. I know I'm not the only one doing this either. If you want to berate newcomers for using physics, make sure there is an obvious alternative that is clearly easier for them.
Perhaps we could have a community physics library, meant as a sort of frontend to love.physics?

Re: Physics tutorial question

Posted: Tue Nov 16, 2010 8:48 pm
by Czrlos
Hi everyone, thank you for your responses so far. Maybe I expressed myself the wrong way but a good example of what I hoped to achieve is the loveavalanche demo that comes with love2d. The balls fall because of the set gravity, colide with each other and with the stairs. I want to spawn one of those balls as the player and move it arround. Can be easily done or is it the same hammer than before?

Re: Physics tutorial question

Posted: Tue Nov 16, 2010 8:49 pm
by Mud
When I started my game, it was much easier to start wildly abusing the physics than it was to figure out and write my own collision system. I know I'm not the only one doing this either.
That's the first thing I did, too. Spawned a bunch of boxes and started knocking them around.