Page 1 of 1

Physics Image Support?

Posted: Sat Jan 08, 2011 8:53 pm
by EMB
Is there a way to have image support for love.physics at the moment? I couldn't find anything on the wiki, but do any of you know a workaround?

Re: Physics Image Support?

Posted: Sat Jan 08, 2011 8:59 pm
by ghostwriter
Can you describe what you mean by image support for love.physics? You can draw images with love.graphics

Re: Physics Image Support?

Posted: Sat Jan 08, 2011 9:09 pm
by tentus
He probably means something along the line of "draw this shape". (Which would be a really useful feature, btw.) You can sort of pull it off using the below:

Code: Select all

width = 64
height = 48
body = love.physics.newBody(world, x, y)
shape = love.physics.newRectangleShape(body, 0, 0, width, height )
love.graphics.rectangle("fill", body:getX() - (width/ 2), body:getY() - (height  / 2), body:getX() + (width/ 2), body:getY() + (height  / 2))
Note that this just draws a rectangle that is the same width and height as the shape, centered on the same pivot. It cannot show you the angle, it just isn't a part of the love.graphics.rectangle function. To do that you will need to make an image (or generate it in Love) and use getAngle() to draw it at the right orientation.

Re: Physics Image Support?

Posted: Sat Jan 08, 2011 10:11 pm
by TechnoCat
tentus wrote:It cannot show you the angle, it just isn't a part of the love.graphics.rectangle function. To do that you will need to make an image (or generate it in Love) and use getAngle() to draw it at the right orientation.
http://love2d.org/wiki/love.graphics.rotate

Re: Physics Image Support?

Posted: Sat Jan 08, 2011 10:54 pm
by ishkabible
using the function mentioned by TechoCat (love.graphics.rotate) and love.graphics.line calls you can make any shape you want. also if you want it to draw the image with physics just get the coordinates of the physics object and the rotations of it and display the image with love.graphics.draw.

Re: Physics Image Support?

Posted: Sat Jan 08, 2011 11:18 pm
by tentus
TechnoCat wrote:
tentus wrote:It cannot show you the angle, it just isn't a part of the love.graphics.rectangle function. To do that you will need to make an image (or generate it in Love) and use getAngle() to draw it at the right orientation.
http://love2d.org/wiki/love.graphics.rotate
I honestly forgot about that one, because I never use it. (I dislike having to store a value, call a function, call the function I originally wanted, and then call a function again with the stored value... it feels like four times the work that simply having an extra parameter in the original function would solve.)

Re: Physics Image Support?

Posted: Sun Jan 09, 2011 12:53 am
by Robin
tentus wrote:I honestly forgot about that one, because I never use it. (I dislike having to store a value, call a function, call the function I originally wanted, and then call a function again with the stored value... it feels like four times the work that simply having an extra parameter in the original function would solve.)
Store a value? push/pop seems like a better fit, especially if you have more transformations going on at the same time.

Re: Physics Image Support?

Posted: Sun Jan 09, 2011 1:43 am
by tentus
I had alpha on my mind when I wrote that, so I didn't even consider push/pop, I should have. Still, that's three lines of code for what could be one.

Re: Physics Image Support?

Posted: Sun Jan 09, 2011 8:51 am
by Robin
tentus wrote:I had alpha on my mind when I wrote that, so I didn't even consider push/pop, I should have. Still, that's three lines of code for what could be one.
It is mostly useful as a different "context", that is if you need to draw more than one object transformed, for example if the whole world rotates, except for the HUD.

Re: Physics Image Support?

Posted: Sun Jan 09, 2011 10:35 am
by EMB
/me is stupid.

I didn't look at the tutorial code properly, and I thought that love.physics automatically drew the shape, as tentus said would be a good feature.
Ignore my question, I now know that I can just draw the shape, draw the image, and make some code to keep them the same x and y.
God I feel so stupid.