Topleft corner...

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.
worfox
Prole
Posts: 3
Joined: Sat Apr 17, 2010 8:46 pm

Topleft corner...

Post 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
Last edited by worfox on Sun Apr 18, 2010 12:03 am, edited 1 time in total.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Topleft corner...

Post by nevon »

You rotate the image by the same angle that the body is rotated.
worfox
Prole
Posts: 3
Joined: Sat Apr 17, 2010 8:46 pm

Re: Topleft corner...

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

Re: Topleft corner...

Post 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
Help us help you: attach a .love.
worfox
Prole
Posts: 3
Joined: Sat Apr 17, 2010 8:46 pm

Re: Topleft corner...

Post 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
Last edited by worfox on Sun Apr 18, 2010 12:42 pm, edited 1 time in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Topleft corner...

Post by bartbes »

worfox wrote: Thanks Robin, it woks :ultrahappy:
Wow, that would be useful code.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Topleft corner...

Post by Robin »

bartbes wrote:
worfox wrote: Thanks Robin, it woks :ultrahappy:
Wow, that would be useful code.
You fail phpBB forever.
Last edited by bartbes on Sun Apr 18, 2010 2:00 pm, edited 3 times in total.
Reason: I have no idea what you're talking about
Help us help you: attach a .love.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Topleft corner...

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

Re: Topleft corner...

Post by Robin »

I doubt that.
Help us help you: attach a .love.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Topleft corner...

Post by nevon »

Robin wrote:I doubt that.
How do you know I didn't look into the future?
Post Reply

Who is online

Users browsing this forum: No registered users and 90 guests