Sprite alignment with rotation

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
User avatar
The Burrito
Party member
Posts: 153
Joined: Mon Sep 21, 2009 12:14 am
Contact:

Sprite alignment with rotation

Post by The Burrito » Thu Oct 08, 2009 2:44 pm

Ok, so I'm sure I'm overlooking something really simple, but how does one go about drawing a sprite to track movement of another object?
This is in version 0.6.0, I understand that images are drawn from their top left, the problem intially came about when I was simply trying to give a physics body a sprite.

Heres an example of what I mean:

Code: Select all

--this is clearly the wrong way to do this.
   love.graphics.draw(tl,x-64,y-64,a)
   love.graphics.draw(tr,x,y-64,a)
   love.graphics.draw(bl,x-64,y,a)
   love.graphics.draw(br,x,y,a)
spritefail.love
(21.96 KiB) Downloaded 43 times
left and right rotate the box, the only point that will maintain proper position relative to the box is br, which is because it's origin is the axis of rotation. So how would I go about making all the images stay in place?

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Sprite alignment with rotation

Post by Robin » Thu Oct 08, 2009 3:11 pm

Add additional arguments for the rotation offset.

EDIT: Actually, depending on what you want--do you want them all to stay inside the larger square? if so, you have to adjust the position where the images are drawn as well, depending on the angle (something like 32*math.sqrt(2)*math.cos(a) for the x, i'm not sure what the correct thing here is).
Help us help you: attach a .love.

User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Sprite alignment with rotation

Post by TechnoCat » Thu Oct 08, 2009 4:32 pm

You might be able to cheat this if you set their centers respectively to the center of the square.

Code: Select all

love.graphics.draw(tl,x,y,a,1,1,64,64)
love.graphics.draw(tr,x,y,a,1,1,0,64)
love.graphics.draw(bl,x,y,a,1,1,64,0)
love.graphics.draw(br,x,y,a,1,1,0,0)
This works because in LOVE 0.6.0 love.graphics.draw now has 2 new parameters for the center:
love.graphics.draw( sprite, x, y, angle, xScale, yScale, xCenter, yCenter)
Attachments
spritefail.love
Edited and working.
(22 KiB) Downloaded 47 times

User avatar
The Burrito
Party member
Posts: 153
Joined: Mon Sep 21, 2009 12:14 am
Contact:

Re: Sprite alignment with rotation

Post by The Burrito » Thu Oct 08, 2009 6:01 pm

TechnoCat wrote:This works because in LOVE 0.6.0 love.graphics.draw now has 2 new parameters for the center:love.graphics.draw( sprite, x, y, angle, xScale, yScale, xCenter, yCenter)
OK, Thanks!

yeah, I figured it was just something I was not familiar with, and that should do perfectly fine for the things I have in mind.

Post Reply

Who is online

Users browsing this forum: No registered users and 39 guests