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
Post
by worfox » Sat Apr 17, 2010 10:52 pm
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?
Last edited by
worfox on Sun Apr 18, 2010 12:03 am, edited 1 time in total.
nevon
Commander of the Circuloids
Posts: 938 Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:
Post
by nevon » Sat Apr 17, 2010 11:25 pm
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
Post
by worfox » Sat Apr 17, 2010 11:52 pm
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!
worfox
Prole
Posts: 3 Joined: Sat Apr 17, 2010 8:46 pm
Post
by worfox » Sun Apr 18, 2010 1:59 am
Thanks Robin, it works
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.
bartbes
Sex machine
Posts: 4946 Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:
Post
by bartbes » Sun Apr 18, 2010 9:44 am
worfox wrote:
Thanks Robin, it woks
Wow, that would be useful code.
Robin
The Omniscient
Posts: 6506 Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:
Post
by Robin » Sun Apr 18, 2010 1:57 pm
bartbes wrote: worfox wrote:
Thanks Robin, it woks
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
nevon
Commander of the Circuloids
Posts: 938 Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:
Post
by nevon » Sun Apr 18, 2010 4:28 pm
bartbes wrote: worfox wrote:
Thanks Robin, it woks
Wow, that would be useful code.
It took me 32 hours to get that joke.
Robin
The Omniscient
Posts: 6506 Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:
Post
by Robin » Sun Apr 18, 2010 4:39 pm
I doubt that.
nevon
Commander of the Circuloids
Posts: 938 Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:
Post
by nevon » Sun Apr 18, 2010 5:49 pm
Robin wrote: I doubt that.
How do you know I didn't look into the future?
Users browsing this forum: Bing [Bot] , Google [Bot] and 1 guest