I was wondering if there was a way to increase the rate at which a repeated input is sent (MOUSE_LEFT).
Currently if i start “drawing” i get the first point instantly (action.pressed), then the second point comes almost a second later (action.repeated) and then the subsequent points are kind of far from each others (every half a second or so).
Is the TOUCH input faster? And if yes, does it work on a computer?
(Note that i didn’t get to try the MOUSE input on a mobile yet)
if action_id == hash("touch") and action.pressed then
-- Do stuff on pressed
elseif action_id == hash("touch") and action.repeated then
-- Do stuff on repeat
end
If you want to check it on repeat then shouldn’t this work for you also?
if action_id == hash("touch") and action.pressed then
-- Do stuff on pressed
elseif action_id == hash("touch") then
-- Do stuff on repeat
end
You could also store the input states in a table and check pressed/released against that table. Something like:
function init(self)
self.action_map = {}
end
function update(self, dt)
if self.action_map[hash("MOUSE_LEFT")] then
-- mouse left if currently pressed
end
end
function on_input(self, action_id, action)
if action.pressed then
self.action_map[action_id] = true
elseif action.released then
self.action_map[action_id] = false
end
end
Inputs are sent every frame. Then there are the additional pressed/released/repeated which are true when:
pressed - input pressed
released - input released
repeated - a software repeated interval timer that mimicks the repeat of a hardware keyboard. There is an initial delay before the repeat kicks in, and then an interval between every true value. This is configured in game.project under “Input”, the values are “Repeat Delay” and “Repeat Interval”.
Ragnar, is it possible to set the delay and interval low enough to guarantee an “action.repeated” every frame?
Never mind, I tried, and yes, delay of 0 and interval set to something really small seems to generate an action.repeated every frame. Can this be guaranteed on all platforms, or would it be better to build a key/action map based on pressed and released events?
The OP tried to use “repeated” and left mouse button to draw something (not sure what) every time. And since repeated didn’t come very often it didn’t work as expected, which is understandable. You could set a flag when left mouse button is pressed and clear it when it is released and use the positional updates of the mouse/touch to do whatever it is the OP wanted to do while the left mouse button was pressed. OR you could set repeat delay and interval to low values and act on repeated events every frame.
I was thinking more along general lines of doing things while a certain action was “pressed”. Things like turning a car or rotating a top-down player while holding down a left/right action. You could do this by setting some variable like self.turning = -1 (or 1) when the left/right action is pressed and set it to 0 when it is released, but you could also gather all pressed/released states into a table and do these checks in the update function where you are probably applying the self.turning value somehow.
That’s true, if you for example need the variable dt in order to add the right amount of speed every frame a car is accelerating. Good point! In other cases, I think it’s good to avoid storing the state unless needed.
i need to handle touch end as well is it ok to use the structure like this. or action could have some another options which i must handle. I check press, then release otherwise assume it’s drag
function on_input(self, action_id, action)
if action_id == TOUCH_MESSAGE and action.pressed then
start_move(self)
elseif action_id == TOUCH_MESSAGE and action.released then
end_move(self)
elseif action_id == TOUCH_MESSAGE then
continue_move(self)
end
end
Yes, exactly. action.repeated is basically only useful if you are making a text-field which you want to act like a native text-field/area where you can hold down a character-key and have it repeat the same character after a short delay.