Page 1 of 1
[SOLVED] Problem with file reading
Posted: Sun Mar 04, 2018 10:00 am
by Le Codex
[SOLVED, look after]
Hi,
I'm currently working on a tile-based movement RPG project, and I would like to scale the game twice as big to make it more pixelated. The problem is, that when I scale up, the textures of the tiles become blurry and dissociated, as well as the player's sprite, as shown by the screenshots:
Scaling x1:
- L1.PNG (5.27 KiB) Viewed 7204 times
Scaling x2:
- L2.PNG (11.25 KiB) Viewed 7204 times
I would like to have the textures still pixelated and not blurry. All the textures files are in .png format.
I remember seeing a similar problem on this forum but I just can't find it anymore. I remember seeing that I could use a canvas on which I would draw everything, then draw the canvas with the scaling, but I have never used canvas before and I don't know how to do it.
I tried
Code: Select all
love.graphics.setDefaultFilter("nearest", "nearest",1)
and it doesn't work for me.
Also here is the .love file, use the arrow keys to move, w to proceed dialogs, x to skip them, mouse wheel to scale up and down:
- 128.love
- (103.32 KiB) Downloaded 181 times
Thanks in advance
(Sorry for my potential bad English, I'm French >.>)
Re: Problem of bluring with scaling
Posted: Sun Mar 04, 2018 10:17 am
by Nixola
You need to call that function before you load any image. I tried running your .love file, but I get the error "Could not open file Graphics/tileset0[].png. Does not exist." (where [] is a character not supported by the font", which shows up as ".png. Does not exist.Could not open file Graphics/tileset0" in the terminal. There's something wrong there.
Re: Problem of bluring with scaling
Posted: Sun Mar 04, 2018 10:26 am
by raidho36
You could use a canvas of desired fixed size and draw everything to it. Then upscale it to the full window size.
Re: Problem of bluring with scaling
Posted: Sun Mar 04, 2018 11:27 am
by Le Codex
Thank you for your responses, I actually managed to fix the scaling problem
However I now have files problem: the game decompiled works juste fine, but when compressed into a .love he isn't able to read the files needed.
Here are the first lines:
Code: Select all
local file = io.open("data/rooms.txt", "r")
rooms = {}
for line in file:lines() do
if line:find("nEw") then
table.insert(rooms, {})
new = true
elseif new then
rooms[#rooms].tileset = line
new = false
else
table.insert(rooms[#rooms], {})
for i=1,line:len() do
table.insert(rooms[#rooms][#rooms[#rooms]], tonumber(line:sub(i, i),36))
end
end
end
When launching it with LÖVE, it says that file is nil, and therefore returns an error at line 3. Is it because it doesn't read inside the .love archive and looks at the folder the .love file is in? If so, how do I fix it?
Also, here is my file tree:
- L3.PNG (7.38 KiB) Viewed 7172 times
Re: Problem with file reading
Posted: Sun Mar 04, 2018 11:34 am
by grump
io.open does not work within a .love archive (plus some other problems). Use
love.filesystem.
Re: Problem with file reading
Posted: Sun Mar 04, 2018 11:46 am
by Le Codex
Oh thank you
I'm playing around with the function right now, but when I try this:
Code: Select all
local file = love.filesystem.newFile("data/rooms.txt")
file:open("r")
rooms = {}
for line in file:lines() do
if line:find("nEw") then
table.insert(rooms, {})
new = true
elseif new then
rooms[#rooms].tileset = line
new = false
else
table.insert(rooms[#rooms], {})
for i=1,line:len() do
table.insert(rooms[#rooms][#rooms[#rooms]], tonumber(line:sub(i, i),36))
end
end
end
file:close()
The .love is stuck in an infinite loop right at the start, and I don't know why. Sorry for bothering you with all my problems :/
Here is the .love file:
- 128.love
- (103.42 KiB) Downloaded 178 times
Re: Problem with file reading
Posted: Sun Mar 04, 2018 11:54 am
by grump
It's better to post a love file that shows the problem. That's easier to look at and saves people from guessing about certain details.
Are you sure it's an infinite loop? How large is rooms.txt? File:lines() is extremely slow in 0.10.2 (edit: when reading from inside a love file), I couldn't use it to read more than a couple hundred lines. Maybe that's your problem - I'm just guessing tho.
It may also help to print out the current line to understand what the code is actually doing.
Re: Problem with file reading
Posted: Sun Mar 04, 2018 12:09 pm
by Le Codex
I added the .love file. In that case, would it better if I keep the data outside of .love file?
rooms.txt has for now only 25 lines, but since it will contain all the data for all the rooms of my game, it will be pretty massive by the end of my project.
Re: Problem with file reading
Posted: Sun Mar 04, 2018 12:20 pm
by grump
File:lines() has another bug that makes it end up in an endless loop when the last line does not end with a newline. rooms.txt is okay, the other text files need a newline at the end.
AFAIK, these bugs will be fixed in the upcoming 0.11 release. You could just keep using lines() until it becomes too slow, and then either switch to 0.11, or replace File:lines() call with File:read() and some parsing to extract the lines yourself. It's not hard to do with string.gmatch, just a couple lines of code.
Re: Problem with file reading
Posted: Sun Mar 04, 2018 12:26 pm
by Le Codex
Thank you for all this information
I'll do what you said, and look for replacing File:lines() with read(), for now it's actually pretty fast