Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a falling blocks type of game with triangular pieces. I'm using a SpriteBatch to accumulate and remember the pieces and their locations.

The problem is that when I rotate a scaled Image of the triangle, I get unexpected results, that is the origin of the sprite rotation is wrong -- but if I rotate a full-size image (no scaling) it works fine. The sprite should rotate from the center of the image (x + xScale * imgWidth / 2) and (y + yScale * imgWidth / 2). When xScale and yScale == 1, everything is fine. But as soon as it scales down to a fraction of the original size, the origin seemingly freaks out to weird sizes. Here's some code to inspect:

function love.load()
    img ="triangle.png")
    sb =, 1024)
    imgWidth = img:getWidth()
    imgHeight = img:getHeight()
    x = 250
    y = 250
    xScale = 0.4
    yScale = 0.4
    xOrig = (xScale * imgWidth / 2)
    yOrig = (yScale * imgHeight / 2)
    angleDirection = 0
    id = sb:add(x, y, math.rad(angleDirection), xScale, yScale, xOrig, yOrig, 0, 0)

function love.update(dt)
    if love.keyboard.isDown(" ") then
        angleDirection = angleDirection + 180
        if angleDirection >= 360 then
            angleDirection = 0
    sb:set(id, x, y, math.rad(angleDirection), xScale, yScale, xOrig, yOrig, 0, 0)

function love.draw()

Now, to see the problem in action, run the preceding code. Change the xScale and yScale to a 1 to see the rotation work properly. Thanks in advance for any suggestions you have.

share|improve this question
Have you tried not scaling the origin of the texture? It may be internally scaling it already in which case you are double doing it. – RobCurr Mar 21 '13 at 21:17
I hadn't thought of that, but will try it out when I get home. Thanks for the suggestion. I'll report back soon. – C. Griffin Mar 21 '13 at 22:03
That actually worked! I was overthinking it, and for some reason it never dawned on me to not scale the origin. If you "answer" my question, I can boost your rep by voting your answer as correct. Thanks again! – C. Griffin Mar 21 '13 at 23:26
up vote 1 down vote accepted

When setting the origin of a scaled image, use the original dimensions of the image instead of the final scaled size. For instance to set the origin to the center of a 200x200 image, you would use 100x100 even if it is scaled as the 'add' and 'set' functionality scale those values internally.

Glad I could help ;)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.