Mimicking behavior of love.keypressed
Posted: Fri Aug 18, 2017 9:56 am
I'm using SiENcE's fabulous midi library to get input from a midi controller. That's working great, but when I put my midi listener in love.update, it seems to interfere with the drawing thread.
For example, here's code that changes the background image when I press the midi note '48':
When I press the note, the screen flashes white for a split second before changing the background image.
It's very brief (I think only one frame) but noticeable enough to be jarring.
I have almost identical code in love.keypressed:
When I press 'w' and it calls next_scene, there's no white flash.
Why does the keypressed function not interfere with the graphics?
Is the keypressed listener running on a separate thread than the main drawing thread or something?
How can I mimic this behavior with a "midi listener"? I tried to figure out how to use a thread to do this but haven't been able to figure threads out from the wiki/forums. Some concrete examples would be most appreciated!
For example, here's code that changes the background image when I press the midi note '48':
Code: Select all
function love.update(dt)
-- do some calculations
a,b,c,d = midi.getMessage(midi_controller_port)
if a == 144 and b == 48 then
next_scene()
end
end
It's very brief (I think only one frame) but noticeable enough to be jarring.
I have almost identical code in love.keypressed:
Code: Select all
function love.keypressed(key, u)
if key == "w" then
next_scene()
end
end
Why does the keypressed function not interfere with the graphics?
Is the keypressed listener running on a separate thread than the main drawing thread or something?
How can I mimic this behavior with a "midi listener"? I tried to figure out how to use a thread to do this but haven't been able to figure threads out from the wiki/forums. Some concrete examples would be most appreciated!