Physics tutorial question

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Czrlos
Prole
Posts: 14
Joined: Wed Nov 10, 2010 9:09 pm

Physics tutorial question

Post by Czrlos » Mon Nov 15, 2010 11:25 pm

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.

User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Physics tutorial question

Post by zac352 » Mon Nov 15, 2010 11:30 pm

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. :|
Hello, I am not dead.

User avatar
ninwa
Party member
Posts: 118
Joined: Tue Oct 12, 2010 1:21 am
Location: Metro Detroit
Contact:

Re: Physics tutorial question

Post by ninwa » Mon Nov 15, 2010 11:37 pm

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.

User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Physics tutorial question

Post by vrld » Mon Nov 15, 2010 11:38 pm

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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Physics tutorial question

Post by zac352 » Mon Nov 15, 2010 11:46 pm

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
Hello, I am not dead.

User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Physics tutorial question

Post by tentus » Tue Nov 16, 2010 6:01 pm

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.
Kurosuke needs beta testers

User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Physics tutorial question

Post by zac352 » Tue Nov 16, 2010 8:12 pm

I'll make a lightweight physics library. Eventually. :P
Hello, I am not dead.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Physics tutorial question

Post by Robin » Tue Nov 16, 2010 8:16 pm

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?
Help us help you: attach a .love.

Czrlos
Prole
Posts: 14
Joined: Wed Nov 10, 2010 9:09 pm

Re: Physics tutorial question

Post by Czrlos » Tue Nov 16, 2010 8:48 pm

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?

User avatar
Mud
Citizen
Posts: 98
Joined: Fri Nov 05, 2010 4:54 am

Re: Physics tutorial question

Post by Mud » Tue Nov 16, 2010 8:49 pm

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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 15 guests