[SOLVED] Problem with file reading

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
Le Codex
Prole
Posts: 31
Joined: Thu Feb 09, 2017 10:56 am
Location: France
Contact:

[SOLVED] Problem with file reading

Post 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
L1.PNG (5.27 KiB) Viewed 7300 times
Scaling x2:
L2.PNG
L2.PNG (11.25 KiB) Viewed 7300 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 >.>)
Last edited by Le Codex on Sun Mar 04, 2018 12:27 pm, edited 3 times in total.

Code: Select all

if your.timeSpeed > 0 then universe:update(dt) else universe:destroy() end
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Problem of bluring with scaling

Post 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.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Problem of bluring with scaling

Post by raidho36 »

You could use a canvas of desired fixed size and draw everything to it. Then upscale it to the full window size.
User avatar
Le Codex
Prole
Posts: 31
Joined: Thu Feb 09, 2017 10:56 am
Location: France
Contact:

Re: Problem of bluring with scaling

Post 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
L3.PNG (7.38 KiB) Viewed 7268 times

Code: Select all

if your.timeSpeed > 0 then universe:update(dt) else universe:destroy() end
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Problem with file reading

Post by grump »

io.open does not work within a .love archive (plus some other problems). Use love.filesystem.
User avatar
Le Codex
Prole
Posts: 31
Joined: Thu Feb 09, 2017 10:56 am
Location: France
Contact:

Re: Problem with file reading

Post 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 192 times
Last edited by Le Codex on Sun Mar 04, 2018 12:03 pm, edited 1 time in total.

Code: Select all

if your.timeSpeed > 0 then universe:update(dt) else universe:destroy() end
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Problem with file reading

Post 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.
User avatar
Le Codex
Prole
Posts: 31
Joined: Thu Feb 09, 2017 10:56 am
Location: France
Contact:

Re: Problem with file reading

Post 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.

Code: Select all

if your.timeSpeed > 0 then universe:update(dt) else universe:destroy() end
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Problem with file reading

Post 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.
User avatar
Le Codex
Prole
Posts: 31
Joined: Thu Feb 09, 2017 10:56 am
Location: France
Contact:

Re: Problem with file reading

Post 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 ^^

Code: Select all

if your.timeSpeed > 0 then universe:update(dt) else universe:destroy() end
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests