Page 1 of 2

Topleft corner...

Posted: Sat Apr 17, 2010 10:52 pm
by worfox
Hey, im new here and I got a problem:

I've got a box shape with a body, and now I want to draw an img over it. I can get the topleft corner with shape:getBoundingBox() if the angle is 0 of the body.
How can I get the topleft corner of a shape, even if it is rotated?

Image

Re: Topleft corner...

Posted: Sat Apr 17, 2010 11:25 pm
by nevon
You rotate the image by the same angle that the body is rotated.

Re: Topleft corner...

Posted: Sat Apr 17, 2010 11:52 pm
by worfox
nevon wrote:You rotate the image by the same angle that the body is rotated.
That's what I did, but it rotates around the topleft corner of the BoundingBox. I need the topleft corner of the shape!

Re: Topleft corner...

Posted: Sun Apr 18, 2010 12:47 am
by Robin
I think what you need to do is to use the offset parameters in love.graphics.draw(): http://love2d.org/wiki/love.graphics.draw

Re: Topleft corner...

Posted: Sun Apr 18, 2010 1:59 am
by worfox
Robin wrote:I think what you need to do is to use the offset parameters in love.graphics.draw(): http://love2d.org/wiki/love.graphics.draw
Thanks Robin, it works :ultrahappy:

How it could work:

Code: Select all

the love.load part:
box = {}
box.img = love.graphics.newImage("img/box.png") --has to be a cube
box.body = love.physics.newBody(world, 325, 100, 30, 1)
box.size = box.img:getWidth( ) 
box.shape = love.physics.newRectangleShape(box.body, 0, 0, box.size, box.size, 0)

the love.draw part:
local x,y = box.body:getPosition()
love.graphics.draw(box.img, x, y, box.body:getAngle( ), 1, 1,box.size/2 ,box.size/2 )-- Offset is half of the size

Re: Topleft corner...

Posted: Sun Apr 18, 2010 9:44 am
by bartbes
worfox wrote: Thanks Robin, it woks :ultrahappy:
Wow, that would be useful code.

Re: Topleft corner...

Posted: Sun Apr 18, 2010 1:57 pm
by Robin
bartbes wrote:
worfox wrote: Thanks Robin, it woks :ultrahappy:
Wow, that would be useful code.
You fail phpBB forever.

Re: Topleft corner...

Posted: Sun Apr 18, 2010 4:28 pm
by nevon
bartbes wrote:
worfox wrote: Thanks Robin, it woks :ultrahappy:
Wow, that would be useful code.
It took me 32 hours to get that joke.

Re: Topleft corner...

Posted: Sun Apr 18, 2010 4:39 pm
by Robin
I doubt that.

Re: Topleft corner...

Posted: Sun Apr 18, 2010 5:49 pm
by nevon
Robin wrote:I doubt that.
How do you know I didn't look into the future?