Problem with using a negative value for scale in love.graphics.draw() when scaling or rotating is used
Posted: Wed Aug 14, 2019 12:20 am
My game uses 32x32 sprites, drawn with an offset of 16 on both the X and Y axes. This is the code used to draw sprites:
(assume image, x, y, and scale are passed in from elsewhere)
This works fine either when scale is 1, or scale isn't 1 for things that don't have angle set or have faceLeft set to true.
In those cases, the image is displaced:
The sprites are all being shifted to the right. The bloodstain sprites are randomly rotated, and seem to shift in whatever direction they've been rotated. (I don't have any non-rotated, non-faceleft sprites in this screenshot to compare, but they are being drawn in the correct place)
I'm assuming the answer is that I need to adjust the offset, but I'm not really sure what it would be changed to. Since a 16px offset works on a 32px sprite, it seems like a 16*scale offset should work with a 32*scale sprite.
Code: Select all
love.graphics.draw(image,x+16,y+16,entity.angle,(entity.faceLeft and -1 or 1)*scale,scale,16*scale,16*scale)
This works fine either when scale is 1, or scale isn't 1 for things that don't have angle set or have faceLeft set to true.
In those cases, the image is displaced:
The sprites are all being shifted to the right. The bloodstain sprites are randomly rotated, and seem to shift in whatever direction they've been rotated. (I don't have any non-rotated, non-faceleft sprites in this screenshot to compare, but they are being drawn in the correct place)
I'm assuming the answer is that I need to adjust the offset, but I'm not really sure what it would be changed to. Since a 16px offset works on a 32px sprite, it seems like a 16*scale offset should work with a 32*scale sprite.