sometimes "touch" event's "began" phase won't fire.

I’m developing rhythm game. and I’m having problems with touch event in Corona SDK.

The problem is, “began” phase won’t fire without any reason.

Touch event is core part of rhythm game.

Can’t reproduce my issue because I can’t find the cause. but it occurs. Especially occurs in the large screen devices.

I turned on the “show touch pointers” at developer option in android settings, and compared coordinates between my touch position and target that I registered the touch listener.

I found this :

when I tap the target, sometimes listener function is not called.

when I move my finger target from then, listener function is called with “moved” phase.

I don’t know why. and can’t fix this problem about 6 month. and reported bug about 3 month ago, and I received reply. they called this bug as “case 34256” and still not fixed.

Please, help me.

And sorry for my bad English.

Can you post your touch code so we can test it out?

for k,v in pairs(coords) do pt\_entities[k] = display.newImageRect("panel\_selected.png",720/4,pHeight/4) group:insert(pt\_entities[k]) pt\_entities[k].x,pt\_entities[k].y = coords[k],coords\_[k] pt\_entities[k].isVisible = false local pt\_ent\_inv = display.newRect(coords[k],coords\_[k],720/4,pHeight/4) pt\_ent\_inv.xScale,pt\_ent\_inv.yScale = math\_min(scene.loadedArea.area,1),math\_min(scene.loadedArea.area,1) pt\_ent\_inv.isVisible = false pt\_ent\_inv.isHitTestable = true group:insert(pt\_ent\_inv) pt\_ent\_inv:addEventListener("touch",function(event) local target = pt\_ent\_inv if(event.phase == "began" or event.phase == "moved") then if(math\_abs(event.x - target.x) \> target.contentWidth/2 or math\_abs(event.y - target.y) \> target.contentHeight/2) then pt\_entities[k].isVisible = false display.getCurrentStage():setFocus(target,nil) end if(math\_abs(event.x - target.x) \< target.contentWidth/2 and math\_abs(event.y - target.y) \< target.contentHeight/2) then pt\_entities[k].isVisible = true display.getCurrentStage():setFocus(target,event.id) touch(k,"") end else pt\_entities[k].isVisible = false display.getCurrentStage():setFocus(target,nil) end return true end) end

sorry for i’m late. this is part of my another game’s touch code. it’s not efficient much because it’s based on my old code. but situation that i wrote occurs.

the size of table ‘coords’ is 16. so I registered 16 touch listener.

Thanks!

I hesitate to evaluate your code as it appears to be quite convoluted and specific to your application. Have you tried going back to square one and testing out a very basic touch listener function? I use basic “began” phase touch listeners and the phases are detected normally. 

The reason I use “moved” phase to detect touch is I need detect finger moved to another button.

Also, I tried use basic “began” phase touch listeners without detect finger move to another button (and I used sample code at docs.coronalabs.com), still 1 “began” phase is not fired per about 30~200 touch event.

I tried to change my code like below.

  • Use widget button to get touch event. Same issue occurs
  • Create 16~100 invisible rect below button and assign listener with returning false. I confirmed the (event phase count = rect count) when touch without error, but when same issue occurred, all rect below button is not respond to my touch. For example, when I created 100 rect below button and touch button, “began” and “moved” and “ended” called 100 times but  all “began” is not fired sometimes. So it’s same as before.
  • Create 1 resolution-size rect and assign 1 listener, and check my button contains event position coordinates. no effect, same issue happened.

What are you setting the width and height to in config.lua? 

What is the screen size of the devices you are testing on?

If you test on a device where the screen size exactly matches the config.lua settings, do you still have a problem?

The width and height setting in config.lua is 720x1280 and portrait.

My device screen size is

7" Nexus 7 2013 (1200x1920)

5.2" LG-G2 F320S (1080x1920)

Screen size isn’t exactly matches the config.lua settings.

Since your physical screen size is larger than the config.lua settings, I wonder how corona sdk handles the mapping. When it comes to detecting movement, it seems like some of the hardware pixels are ignored. If that’s the case, maybe some of them are also ignored when you start a touch.

Can you post your touch code so we can test it out?

for k,v in pairs(coords) do pt\_entities[k] = display.newImageRect("panel\_selected.png",720/4,pHeight/4) group:insert(pt\_entities[k]) pt\_entities[k].x,pt\_entities[k].y = coords[k],coords\_[k] pt\_entities[k].isVisible = false local pt\_ent\_inv = display.newRect(coords[k],coords\_[k],720/4,pHeight/4) pt\_ent\_inv.xScale,pt\_ent\_inv.yScale = math\_min(scene.loadedArea.area,1),math\_min(scene.loadedArea.area,1) pt\_ent\_inv.isVisible = false pt\_ent\_inv.isHitTestable = true group:insert(pt\_ent\_inv) pt\_ent\_inv:addEventListener("touch",function(event) local target = pt\_ent\_inv if(event.phase == "began" or event.phase == "moved") then if(math\_abs(event.x - target.x) \> target.contentWidth/2 or math\_abs(event.y - target.y) \> target.contentHeight/2) then pt\_entities[k].isVisible = false display.getCurrentStage():setFocus(target,nil) end if(math\_abs(event.x - target.x) \< target.contentWidth/2 and math\_abs(event.y - target.y) \< target.contentHeight/2) then pt\_entities[k].isVisible = true display.getCurrentStage():setFocus(target,event.id) touch(k,"") end else pt\_entities[k].isVisible = false display.getCurrentStage():setFocus(target,nil) end return true end) end

sorry for i’m late. this is part of my another game’s touch code. it’s not efficient much because it’s based on my old code. but situation that i wrote occurs.

the size of table ‘coords’ is 16. so I registered 16 touch listener.

Thanks!

I hesitate to evaluate your code as it appears to be quite convoluted and specific to your application. Have you tried going back to square one and testing out a very basic touch listener function? I use basic “began” phase touch listeners and the phases are detected normally. 

The reason I use “moved” phase to detect touch is I need detect finger moved to another button.

Also, I tried use basic “began” phase touch listeners without detect finger move to another button (and I used sample code at docs.coronalabs.com), still 1 “began” phase is not fired per about 30~200 touch event.

I tried to change my code like below.

  • Use widget button to get touch event. Same issue occurs
  • Create 16~100 invisible rect below button and assign listener with returning false. I confirmed the (event phase count = rect count) when touch without error, but when same issue occurred, all rect below button is not respond to my touch. For example, when I created 100 rect below button and touch button, “began” and “moved” and “ended” called 100 times but  all “began” is not fired sometimes. So it’s same as before.
  • Create 1 resolution-size rect and assign 1 listener, and check my button contains event position coordinates. no effect, same issue happened.

What are you setting the width and height to in config.lua? 

What is the screen size of the devices you are testing on?

If you test on a device where the screen size exactly matches the config.lua settings, do you still have a problem?

The width and height setting in config.lua is 720x1280 and portrait.

My device screen size is

7" Nexus 7 2013 (1200x1920)

5.2" LG-G2 F320S (1080x1920)

Screen size isn’t exactly matches the config.lua settings.

Since your physical screen size is larger than the config.lua settings, I wonder how corona sdk handles the mapping. When it comes to detecting movement, it seems like some of the hardware pixels are ignored. If that’s the case, maybe some of them are also ignored when you start a touch.