@@ -39,7 +39,24 @@ function M.create(config)
3939 }
4040 return data
4141 end
42-
42+
43+ local function enable_multitouch (touch_list )
44+ if multitouch_enabled then
45+ return
46+ end
47+ multitouch_enabled = true
48+ -- Find the touch with `id == config.touch` to upgrade to multitouch, i.e.
49+ -- replace its id with the first touch from the `touch_list` list.
50+ for _ ,control in pairs (controls ) do
51+ if control .touch_index == config .touch then
52+ for _ , v in pairs (touch_list ) do
53+ control .touch_index = v .id
54+ return
55+ end
56+ end
57+ end
58+ end
59+
4360 local function handle_button (control , node )
4461 if control .pressed then
4562 control .fn (M .BUTTON_PRESSED , node , create_data (control ))
@@ -213,12 +230,12 @@ function M.create(config)
213230 function instance .on_input (action_id , action )
214231 assert (action , " You must provide an action table" )
215232 if action .touch then
216- multitouch_enabled = true
233+ enable_multitouch ( action . touch )
217234 for i ,tp in pairs (action .touch ) do
218235 handle_touch (tp , tp .id )
219236 end
220237 elseif action_id == config .touch and not multitouch_enabled then
221- handle_touch (action , 0 )
238+ handle_touch (action , config . touch )
222239 end
223240 end
224241
@@ -248,4 +265,4 @@ function M.on_input(action_id, action, instance)
248265 return instance .on_input (action_id , action )
249266end
250267
251- return M
268+ return M
0 commit comments