Physics Image Support?

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.
Post Reply
EMB
Citizen
Posts: 70
Joined: Sat Jan 08, 2011 8:49 pm

Physics Image Support?

Post 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?
Request Programs
If Linux were a beer, it would be shipped in open barrels so that anybody could piss in it before delivery
User avatar
ghostwriter
Prole
Posts: 38
Joined: Sat Dec 11, 2010 11:08 pm

Re: Physics Image Support?

Post by ghostwriter »

Can you describe what you mean by image support for love.physics? You can draw images with love.graphics
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Physics Image Support?

Post 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.
Kurosuke needs beta testers
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Physics Image Support?

Post 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
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: Physics Image Support?

Post 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.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Physics Image Support?

Post 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.)
Kurosuke needs beta testers
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Physics Image Support?

Post 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.
Help us help you: attach a .love.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Physics Image Support?

Post 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.
Kurosuke needs beta testers
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Physics Image Support?

Post 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.
Help us help you: attach a .love.
EMB
Citizen
Posts: 70
Joined: Sat Jan 08, 2011 8:49 pm

Re: Physics Image Support?

Post 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.
Request Programs
If Linux were a beer, it would be shipped in open barrels so that anybody could piss in it before delivery
Post Reply

Who is online

Users browsing this forum: pgimeno and 63 guests