Lost runtime touch events between scene change

Hello guys,

Sorry to bother but I just hit what seems to be a dead end in my search for “the lost event” :slight_smile:

Here is a quick summary of the issue:

My goal : manage the continuity of my on-screen d-pad position between scene changes

(i.e. my user can keep its thumb on it or release it whenever he wants)

My problem : touch events happening while destroying scene 1 and loading scene 2 are never received

by my ‘Runtime listener’ even if it is not removed (nor re-added).

It is especially problematic for lost ‘ended’ events as my d-pad will keep its last value and move the character

even if my user is no longer pressing the pad.

My context : I use the following state machine for my scene changes:

game.lua (params = level_1) -> loader.lua (params = level_2) -> game.lua (params = level_2)

As I need to re-call the ‘create()’ function of my scene, at each change I call:

    composer.removeScene( “nextScene”, false )

    composer.gotoScene(“nextScene”, …)

Regarding my listener, I use (once):

    Runtime:addEventListener( “touch”, M.onTouch )

I made sure it is never removed (by me at least) and even tried to require its file/class as a global variable

from ‘main.lua’ but it doesn’t change anything. FYI, I works prefectly well before and after the scene switch.

It is just between that the events stop coming…

Note: it seems the runtime key listener (from my ‘main.lua’) keeps working while switching

I hope I gave you enough info. If not, please do not hesitate.

I suspect an issue with the ‘composer’ API itself so I will be glad to hear from you guys.

Thanks,

Go-G

I have the exact same problem and searches haven’t helped.  If I keep held down a direction button with a listener between scenes the sprite being controlled continues to move and this will continue across further scenes indefinitely.

I’ve not revisited it for a long time but my only solution when I first encountered it was to forcibly move the sprite on the next screen, which seemed to have the effect of booting it out of this effect.  However, it’s not a fulproof approach.   I imagine there must be a simple fix for this that I don’t understand.

I’m surprised this hasn’t come up much.

Are you displaying the D-pad as an overlay, or are you switching between two separate but identical sprites that have the same screen coordinates? 

Not sure what the OP has done and don’t want to hijack their post but I think we have an issue that’s probably solved in the same way.

Whenever I’ve used a dpad I either have a dpad split into 4 images that are checked or I do an invisible overlay of images over the dpad.  In my current setup I have only left and right movement which are currently only controlled by two large invisible rectangles each side of the screen with touch event listeners calling a function on each one in the top display group.

At the moment I have identical code in both scenes (with logic to determine the (Tiled) map to select) so the scene is actually destroyed and restarted afresh which I’d have thought would have guaranteed there being no danger of anything staying in memory between the two scenes.  I do intend to switch to a dummy scene on transitions to simplify this to become just a single scene controlling every map soon.

Given it’s restarting the next scene completely fresh my thoughts are that I am in some way not allowing the event from the first scene to disappear by holding on it and some part of the listener gets destroyed which would have detected the cancel/end phase of the touch event but has left something behind that causes the function in the next scene to think the event is still live.

Are you setting display.getCurrentScene():setFocus()?  At this point, all touch events will get funnelled to the D-Pad object?  If the scene is destroyed without releasing the focus, maybe Corona is still trying to send all touch events to a nil object?

Hello all,

Thanks for your replies and advice.

I’m curently working on another project so I didn’t take time to test further solutions yet.

I don’t use any ‘setFocus’ calls nor a listener associated with my D-Pad object.

My implementation is based on a ‘runtime’ event listener that is not destroyed when I switch scenes (I checked).

It works fine before and after switching but not between (no event received during the “goto”).

The workaround I was thinking about was not to switch scene at all and handle the map swap

directly inside the same scene (not exactly a proper solution, is it ?).

Note: I use a “fade in” transition between my scenes with a black background in my dummy loader scene

to create a “fade to black” effect (works quite well). Not sure if it has any impact on this issue…

If their is no solution available then, I’ll try to post a basic sample to reproduce the issue when I get

back working on my second project (not sure when still). 

Hope this helps and don’t hesitate to contribute if anybody has the same problem or a potential solution.

Thanks,

Go-G

fyi: composer (storyboard too) puts up an invisible rect to intercept touch/tap during transition

I have the exact same problem and searches haven’t helped.  If I keep held down a direction button with a listener between scenes the sprite being controlled continues to move and this will continue across further scenes indefinitely.

I’ve not revisited it for a long time but my only solution when I first encountered it was to forcibly move the sprite on the next screen, which seemed to have the effect of booting it out of this effect.  However, it’s not a fulproof approach.   I imagine there must be a simple fix for this that I don’t understand.

I’m surprised this hasn’t come up much.

Are you displaying the D-pad as an overlay, or are you switching between two separate but identical sprites that have the same screen coordinates? 

Not sure what the OP has done and don’t want to hijack their post but I think we have an issue that’s probably solved in the same way.

Whenever I’ve used a dpad I either have a dpad split into 4 images that are checked or I do an invisible overlay of images over the dpad.  In my current setup I have only left and right movement which are currently only controlled by two large invisible rectangles each side of the screen with touch event listeners calling a function on each one in the top display group.

At the moment I have identical code in both scenes (with logic to determine the (Tiled) map to select) so the scene is actually destroyed and restarted afresh which I’d have thought would have guaranteed there being no danger of anything staying in memory between the two scenes.  I do intend to switch to a dummy scene on transitions to simplify this to become just a single scene controlling every map soon.

Given it’s restarting the next scene completely fresh my thoughts are that I am in some way not allowing the event from the first scene to disappear by holding on it and some part of the listener gets destroyed which would have detected the cancel/end phase of the touch event but has left something behind that causes the function in the next scene to think the event is still live.

Are you setting display.getCurrentScene():setFocus()?  At this point, all touch events will get funnelled to the D-Pad object?  If the scene is destroyed without releasing the focus, maybe Corona is still trying to send all touch events to a nil object?

Hello all,

Thanks for your replies and advice.

I’m curently working on another project so I didn’t take time to test further solutions yet.

I don’t use any ‘setFocus’ calls nor a listener associated with my D-Pad object.

My implementation is based on a ‘runtime’ event listener that is not destroyed when I switch scenes (I checked).

It works fine before and after switching but not between (no event received during the “goto”).

The workaround I was thinking about was not to switch scene at all and handle the map swap

directly inside the same scene (not exactly a proper solution, is it ?).

Note: I use a “fade in” transition between my scenes with a black background in my dummy loader scene

to create a “fade to black” effect (works quite well). Not sure if it has any impact on this issue…

If their is no solution available then, I’ll try to post a basic sample to reproduce the issue when I get

back working on my second project (not sure when still). 

Hope this helps and don’t hesitate to contribute if anybody has the same problem or a potential solution.

Thanks,

Go-G

fyi: composer (storyboard too) puts up an invisible rect to intercept touch/tap during transition