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?
Topleft corner...
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Topleft corner...
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:
Re: Topleft corner...
You rotate the image by the same angle that the body is rotated.
Re: Topleft corner...
That's what I did, but it rotates around the topleft corner of the BoundingBox. I need the topleft corner of the shape!nevon wrote:You rotate the image by the same angle that the body is rotated.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Topleft corner...
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.
Re: Topleft corner...
Thanks Robin, it worksRobin 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
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:
Re: Topleft corner...
Wow, that would be useful code.worfox wrote: Thanks Robin, it woks
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Topleft corner...
You fail phpBB forever.bartbes wrote:Wow, that would be useful code.worfox wrote: Thanks Robin, it woks
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
Reason: I have no idea what you're talking about
Help us help you: attach a .love.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Topleft corner...
It took me 32 hours to get that joke.bartbes wrote:Wow, that would be useful code.worfox wrote: Thanks Robin, it woks
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Topleft corner...
How do you know I didn't look into the future?Robin wrote:I doubt that.
Who is online
Users browsing this forum: RetroKevin and 14 guests