LÖVE has only one mousepressed callback function which is love.mousepressed, so my game's code of controllings with mouse all will put in there? Mouse controllings has varied uses in varied situations, so it's hard to manage it in one function. And the keyboard and touch are also, but at least I could make it work. So what do you do to it?
Because I had never used suchlike framework...it may sound silly
[Solved] Game Controlling Question
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[Solved] Game Controlling Question
Last edited by ceana on Sun Aug 13, 2017 4:52 am, edited 1 time in total.
Re: [Newbie] Game Controlling Question
You can change the mousepressed handler if you want to activate a different behaviour during your game.
Here's a most simple example that first defines two different handlers and then activates the first one as a default in the last line. It then just toggles between the two based on the pressed mouse button to show you how it could be done.
Here's a most simple example that first defines two different handlers and then activates the first one as a default in the last line. It then just toggles between the two based on the pressed mouse button to show you how it could be done.
Code: Select all
function menuMousePressed( x, y, button, isTouch )
-- do your menu stuff here
if button == 1 then
love.mousepressed = ingameMousePressed
end
end
function ingameMousePressed( x, y, button, isTouch )
-- handle ingame mouse here
if button == 2 then
love.mousepressed = menuMousePressed
end
end
love.mousepressed = menuMousePressed
Re: [Newbie] Game Controlling Question
Nelvin is on the right track, although a "cleaner" solution might be to just pass all of the input to the current state.
So instead of changing the callback, you react to the input events, based on the current "state" of the game:
Of course you can always avoid callbacks and check if the mouse button is pressed whenever you need, depending on the context.
So instead of changing the callback, you react to the input events, based on the current "state" of the game:
Code: Select all
function love.mousepressed(...)
state.press(...)
end
states = {}
states.menu = {}
function states.menu.press(x,y,b,t)
-- do menu stuff
end
states.play = {}
function states.play.press(x,y,b,t)
-- do in-game stuff
end
state = states.menu
Re: [Newbie] Game Controlling Question
I have an input library that greatly simplifies the whole deal, maybe it will help you.
Re: [Newbie] Game Controlling Question
Thanks for everyone's help and idea!
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests