Threads on 0.9.0
Posted: Sat Dec 28, 2013 10:41 pm
Hello everybody!
I'm making a game in which the world is generated randomly and it's infinite. I generate a 640x480 level png image when I need to and save it to a local folder.
The problem is that I need to reload these images on the fly as the game is running.
I figured out I need to use threads to load this images. The problem is that I don't know much about threads on LÖVE.
I have this on my main.lua
And this on my thread.lua
I create a channel and a thread. I start the thread which is waiting for the filepath of the image. I push "uno.png" to the channel. This should trigger the demand() in the thread and should pop the value from the channel. Next the main file is waiting for a value on the channel, which I push in the thread file.
So the IMG variable should contain an image object.
But the print in the main.lua file it's printing "uno.png", as no thread loaded any image.
What am I doing wrong?
I'm making a game in which the world is generated randomly and it's infinite. I generate a 640x480 level png image when I need to and save it to a local folder.
The problem is that I need to reload these images on the fly as the game is running.
I figured out I need to use threads to load this images. The problem is that I don't know much about threads on LÖVE.
I have this on my main.lua
Code: Select all
channel = love.thread.getChannel("CHAN1");
thread = love.thread.newThread("thread.lua");
thread:start(); channel:push("uno.png");
IMG = channel:demand();
print(IMG);
Code: Select all
local channel = love.thread.getChannel("CHAN1");
local file = channel:demand();
local img = love.graphics.newImage(file);
channel:push(img);
So the IMG variable should contain an image object.
But the print in the main.lua file it's printing "uno.png", as no thread loaded any image.
What am I doing wrong?