[Resolved] Touch event driving me crazyyyy!

Hi, I am almost there - just this bug left and then we are “Go” for appstore. But I keep banging my head against this one and I have no more options left to try, I desperately need some help here!

So, on my screen I have two objects that responds to “touches”. I have one navigation button, one character. If i hammer each object rapidly they work as they should. The first thing I do when an object is touched, is to remove all eventListeners for all objects, and then I creates them back with a small delay.

The problem occurs when I start hammering both the character and the navigation icon. After a couple of seconds everything starts to mess up in my game. I guessing that I am getting tons of eventListeners here and thats why the game cracks up. This is a game for children and I can guess that they love to hammer that iPad :confused:

I have tried everything from setFocus on objects - both the target in the began event, and then setFocus to nil in the ended event, I have changed order of code, I have done everything I could possible think of.

Anyone out here that got a bulletproof idea of how I should manage to get this to work? [import]uid: 81188 topic_id: 31832 reply_id: 331832[/import]

Not sure what you’re trying to accomplish during the “hammering” phase and whether you’re trying to ignore subsequent events that aren’t part of the first event or what…but we’ve used something like this to accomplish certain things (writing this from memory, hope it works :slight_smile: )

[code]

if button.touchId == nil and event.phase == “began” then
button.touchId = event.id
display.getCurrentStage():setFocus(event.target, event.id)
elseif event.phase == “moved” then
elseif (event.phase == “ended” or event.phase == “cancelled”) and button.touchId = event.id then
button.touchId = nil;
display.getCurrentStage():setFocus(event.target, nil)
end
[/code] [import]uid: 105599 topic_id: 31832 reply_id: 127023[/import]

@jkrassman, I’m wondering if you tried not to remove and create eventListeners. If not, how about if you give “isActive” property (or some other custom property, like touchOn) to the objects, and use true/false statement to either trigger or not trigger whatever it is the touch is supposed to do? At least, this way, you wouldn’t have bazillions of eventListeners get attached to your objects.

In the same token, you could, instead, use the same true/false statement to check if eventListeners are already attached to the objects. So… remove eventListener and set isActive to false, and when you attached the eventListener, set isActive to true. When isActive is true, don’t create another one…

Dunno if this works for you, but it’s my two cents worth.

Naomi
[import]uid: 67217 topic_id: 31832 reply_id: 127024[/import]

Thanks, thanks, thanks to you both - that did the trick for me and everything works as it should now!

You really helped me out here and “Corona” love to you all!

Joakim [import]uid: 81188 topic_id: 31832 reply_id: 127028[/import]

So which one did the trick?
[import]uid: 12407 topic_id: 31832 reply_id: 127033[/import]

A combination of them both actually :slight_smile:

Joakim [import]uid: 81188 topic_id: 31832 reply_id: 127036[/import]

Not sure what you’re trying to accomplish during the “hammering” phase and whether you’re trying to ignore subsequent events that aren’t part of the first event or what…but we’ve used something like this to accomplish certain things (writing this from memory, hope it works :slight_smile: )

[code]

if button.touchId == nil and event.phase == “began” then
button.touchId = event.id
display.getCurrentStage():setFocus(event.target, event.id)
elseif event.phase == “moved” then
elseif (event.phase == “ended” or event.phase == “cancelled”) and button.touchId = event.id then
button.touchId = nil;
display.getCurrentStage():setFocus(event.target, nil)
end
[/code] [import]uid: 105599 topic_id: 31832 reply_id: 127023[/import]

@jkrassman, I’m wondering if you tried not to remove and create eventListeners. If not, how about if you give “isActive” property (or some other custom property, like touchOn) to the objects, and use true/false statement to either trigger or not trigger whatever it is the touch is supposed to do? At least, this way, you wouldn’t have bazillions of eventListeners get attached to your objects.

In the same token, you could, instead, use the same true/false statement to check if eventListeners are already attached to the objects. So… remove eventListener and set isActive to false, and when you attached the eventListener, set isActive to true. When isActive is true, don’t create another one…

Dunno if this works for you, but it’s my two cents worth.

Naomi
[import]uid: 67217 topic_id: 31832 reply_id: 127024[/import]

Thanks, thanks, thanks to you both - that did the trick for me and everything works as it should now!

You really helped me out here and “Corona” love to you all!

Joakim [import]uid: 81188 topic_id: 31832 reply_id: 127028[/import]

So which one did the trick?
[import]uid: 12407 topic_id: 31832 reply_id: 127033[/import]

A combination of them both actually :slight_smile:

Joakim [import]uid: 81188 topic_id: 31832 reply_id: 127036[/import]