Center image and resize to actual size

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
Posts: 1
Joined: Tue Apr 21, 2020 4:16 am

Center image and resize to actual size

Post by Lynnstrum » Tue Apr 21, 2020 4:22 am

Hello, I am trying to place a image in my game and have no idea what I'm doing lol.
I want it in the center of the screen, and the size of the actual image.
Instead, I get a really, really big image and not at all in the center.
This is my code:

Code: Select all

gReward ='goldReward.png')
quad =, 0, 128, 64, gReward:getWidth(), gReward:getHeight()), 100, 100, 0, 1, 1, VIRTUAL_WIDTH / 2, VIRTUAL_HEIGHT / 2)

Thank you! Please explain how it works too please.
I don't just want the correct code, I want to understand why it's correct!

User avatar
Posts: 5
Joined: Sun Dec 15, 2019 1:16 pm

Re: Center image and resize to actual size

Post by MynameisBI » Tue Apr 21, 2020 4:15 pm

Hello there.

So firstly, you're actually mistaken the last 2 offsets arguments of the function. These 2 arguments basically say substract the VIRTUAL_WIDTH / 2 from the 100.
Assuming the scale is normal 1:1, LOVE will then draw the image at coordinate 100 - VIRTUAL_WIDTH/2, which is why the image isn't at the center of the screen.
What you can use instead, assuming VIRTUAL_WIDTH is the screen width, is:

Code: Select all, VIRTUAL_WIDTH / 2, VIRTUAL_HEIGHT / 2, 0, 1, 1, gReward:getWidth() / 2, gReward:getHeight() / 2)
Which tell LOVE to first draw the top left of the image at the center, after that offsets the image a value equal to half its size

And about the size of the image, I don't see anything wrong with your code. Could you attach a .love file so I can take a look?

User avatar
Party member
Posts: 2913
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary

Re: Center image and resize to actual size

Post by zorg » Thu Apr 23, 2020 2:30 pm

i see the udemy or whatever course makes people think the push library is inherently needed to make a game...
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

User avatar
Posts: 54
Joined: Mon Mar 09, 2020 2:26 pm

Re: Center image and resize to actual size

Post by Varkas » Fri Apr 24, 2020 1:13 am

I wonder too, how many are using virtual resolutions and struggle with the intricate details that come with it. Retina displays?
In soviet russia, code debugs you.

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests