# Love2D : Problem rotating image in a SpriteBatch

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 = love.graphics.newImage("triangle.png")
sb = love.graphics.newSpriteBatch(img, 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)
end

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

function love.draw()
love.graphics.draw(sb)
end


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.

• 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. 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. 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! Mar 21 '13 at 23:26