resize image at load

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
User avatar
Lirija
Prole
Posts: 28
Joined: Tue Mar 14, 2017 11:42 am
Contact:

resize image at load

Post by Lirija »

Hello everyone, i really hope you can help me with this one:
basicly i have this 24x24 sprite and the window size is 640x480;
i'd like to know if there is a way to load the image bigger as it is, or something like that.
(I'm quite a noob so unfortunately i don't even know the terminology / what i should google for ).

I asked how to load a resized image as i managed the collision using img:getWidth() / img:getHeight() and just changing the scaling in love.graphics.draw messes up with the game logic.

(I'm sorry if the english is not that good but i'm not a native speaker. :( I hope this is still understandable.)
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: resize image at load

Post by ivan »

Ok, so there are a few simple solutions but you're not going to like them.
1. You can resize/scale images while drawing
2. Don't base your game logic on images and how you draw things.
Just use custom units for your game logic, like meters and convert those to pixels when you want to draw stuff.
If your game is programmed well you should be able to run it as a simulation - without any graphics at all.
User avatar
Lirija
Prole
Posts: 28
Joined: Tue Mar 14, 2017 11:42 am
Contact:

Re: resize image at load

Post by Lirija »

First thing first thanks for the answer;

1. do you mean love.graphics.draw(img,x,y,0,scale_x,scale_y) or something like exporting 400% from aseprite? (because i was about to do the latter until i realized that this looked like something a computer could do at runtime and posted the question)

2. Why shouldn't I? I don't get the cons

Anyway in the end i displayed everthing 1:1 in a bigger window and upscaled with the camera module
(using img:setFilter("nearest","nearest"))
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: resize image at load

Post by ivan »

1. Yes, that should work, but it scales your image by a fraction so scale = 2 would draw your object twice as large.
Exporting your image at 400% is not good because it wastes RAM and is slower to load.
If you want to scale multiple sprites, there is also: love.graphics.scale

2. It's not a big deal for small projects, but it's important for long term maintance.
For example, in the future you may want to change how your game renders stuff, and you don't want that to affect your game logic.
You see, when you separate your game logic from the rendering code, you'll have two different, independent systems. This way you can make small isolated changes without playtesting the entire game every time.
On the other hand, when everything is interdependent (or "coupled") then one small change will affect your whole project.
User avatar
Lirija
Prole
Posts: 28
Joined: Tue Mar 14, 2017 11:42 am
Contact:

Re: resize image at load

Post by Lirija »

Ok i think i got it, thank you for the tips!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 45 guests