I’m debugging a rare issue where input is sometimes blocked. I stumbled on an issue that might be related. If the mouse is pressed and held, then released and quickly pressed again that input is ignored by Defold.
I thought I was imagining things until I recorded it with quicktime, which shows the actual input. Around 4 seconds in, the press input is ignored:
I am able to reproduce it consistently. I’m using MacOS.
Yes, those are remnants from a different project. They don’t affect the issue, which is still there, though.
To remove any question marks about the code, here is a clean version with no reference to the old project (I hope!):
function on_input(self, action_id, action)
pprint("on_input", self, action_id, action)
if action_id == hash("touch") and action.pressed then
-- Print touches
local str = table_print( action )
local pos = vmath.vector3(action.screen_x,action.screen_y,0)
msg.post("@render:", "draw_debug_text", { text = str, position = pos, color = vmath.vector4() } )
--
-- Create sprite
local game_object = factory.create("go#factory")
local distance = 200
local degrees = math.random(360)
local radians = math.rad(degrees)
local x = action.x + math.cos(radians) * distance
local y = action.y + math.sin(radians) * distance
go.set_position(vmath.vector3(x,y,0),game_object)
-- Tint sprite
local sprite = msg.url(nil,game_object,"sprite")
local r = math.random(255)/255
local g = math.random(255)/255
local b = math.random(255)/255
go.set(sprite, "tint", vmath.vector4(r,g,b,1))
-- Animate sprite
go.animate(game_object, "position", go.PLAYBACK_ONCE_FORWARD, vmath.vector3(action.x,action.y,0), go.EASING_INOUTSINE, 0.25, 0, function()
go.delete(game_object)
end)
end
end
Then stripped off the project from all the noise, reduced it to:
function init(self)
msg.post(".", "acquire_input_focus")
end
local touches = 0
function on_input(self, action_id, action)
--if action.pressed then
if action_id == hash('touch' ) and action.pressed then
-- Print touches
touches = touches + 1
print('pressed',touches )
end
end
Then the issue is there when I release the mouse click and click again quickly happening in a single frame!
Hmm, I’d need to read the code to understand more what’s happening, but also, I could interpret the documentation differently. The input action is a state, in the input system, and each frame it’s updated with the input (keys/mouse/etc). And, then, if it was altered, it fires an “on_input()”. That is, only once per frame per action (not per key press!).
That’s interesting. Does this mean a release and a press input on the same frame only reports release OR press? Could this be why only the release is fired, and not press in the video?
Hi @Mathias_Westerdahl. If the engine is reporting the state then is expected to happen what we are seeing, because when in a single frame I release a button and press it again there is no change in the state from outside. But, I don’t believe this behaviour is the most acceptable, because I can think of few cases where the user could fall in that particular situation and the game not responding as they wished.
While the game is at 60fps or more the occurrence of this is less probable, then this can pass unnoticeable for a long time.
I can also confirm by my few tests that the report of pressed and released keep consistent , every “pressed” has later a “released” keeping the same number of both. The miss is when they both happen during the same frame.
So, it looks like if a released and pressed happen during the same frame, neither the pressed nor released are reported. In the video below I print every action.released and action.pressed that come through:
It would be great if you could create a GitHub issue so we don’t lose track of this. Please include as much info as possible, steps to reproduce, test app, link to this discussion etc
Any news about the correction of entries in macos? It happens to me too and it’s annoying, I’m not considering launching the version in macos for this reason since it prevents you from pressing buttons on certain occasions, and it gives the feeling that the application does not work good.