I have an image that scales when the player collides with it, as a simple animation for when the player bounces off.
However, i can't figure out what to put as the offset for love.graphics.draw()
Here's a stripped down bit of code showing what i'm trying to achieve;
The problem: the image should always be centred on the orange box, no matter what the scale is. How can i calculate to draw the image like this using the offset parameters?
[solved] How do i offset an image so that it centres properly with scale?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[solved] How do i offset an image so that it centres properly with scale?
Last edited by unixfreak on Tue Jan 30, 2018 2:53 am, edited 1 time in total.
Re: How do i offset an image so that it centres properly with scale?
Get the center point of the image. Add it to the drawing coords, and set the origin to the coordinates of the center point:
Code: Select all
local ox, oy = bumper.w * .5, bumper.h * .5 -- get center point
love.graphics.draw(
bumper.gfx, -- texture
bumper.x + ox, -- x pos
bumper.y + oy, -- y pos
0, -- rotation
bumper.scale, -- x scale
bumper.scale, -- y scale
ox,
oy
)
Re: How do i offset an image so that it centres properly with scale?
For some reason i was trying to use the x/y values within the offset value itself, which obviously wouldn't work. Your method is perfect.
Thank you so much.
Who is online
Users browsing this forum: Google [Bot] and 208 guests