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

### Center image and resize to actual size

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 = love.graphics.newImage('goldReward.png')

love.graphics.draw(gReward, 100, 100, 0, 1, 1, VIRTUAL_WIDTH / 2, VIRTUAL_HEIGHT / 2)


I don't just want the correct code, I want to understand why it's correct!

MynameisBI
Prole
Posts: 5
Joined: Sun Dec 15, 2019 1:16 pm

### Re: Center image and resize to actual size

Hello there.

So firstly, you're actually mistaken the last 2 offsets arguments of the love.graphics.draw 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

love.graphics.draw(gReward, 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?

zorg
Party member
Posts: 2914
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: Center image and resize to actual size

i see the udemy or whatever course makes people think the push library is inherently needed to make a game...
Me and my stuff True 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.

Varkas
Citizen
Posts: 54
Joined: Mon Mar 09, 2020 2:26 pm

### Re: Center image and resize to actual size

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.

### Who is online

Users browsing this forum: No registered users and 35 guests