Multiple event calls with Tap and Touch..

I’m seeing 2 entrances into my ‘Tap’ eventListener function instead of the 1 I expected. Happens with ‘Touch’ events as well.

I’ve created a circle object to act as a button and added the eventListener() to that object. When I tap using the simulator the function is entered twice for 1 ‘tap’ (click). I put a print() into the function to proved this to myself.

The button object is drawn on top of a larger screen image. The screen image doesn’t have an eventListener assigned.

If anyone has a quick ‘hey, dummy, did you do this?’ answer I would appreciate it. :wink:

I can post the code if it’s not an obvious stupid User issue.

Thanks in advance!

Sounds like you attached the ‘tap’ listener more than once.  

i.e. This will produce two tap events for one object:

local onTap( self ) print("Tap at time", system.getTimer() ) end local player = display.newCircle( 100, 100, 20 ) player.tap = onTap player:addEventListener("tap") player:addEventListener("tap") -- Now, tapping the listener gives two events (on that object) for every tap.

Also, while tap listeners are very basic, touch listenners has phases (began, moved, ended, …)  if you ignore those then it will seem like you’re getting mulitiple touches when you are just getting the phases of the touch.

I will check that out, but I don’t believe that’s my problem.

I think I’m doing this, based on one of the code examples. Sorry, I don’t have my project in front of my right now.

Also, I believe I’m doing all my eventListener() attachments like this…

local function onTap(e)

end

local player = display.newCircle( 100, 100, 20 )

player:addEventListener(“tap”, onTap)

I just picked this project back up from last year when it was storyboard based and I’m trying to update it to composer. I finally have some time to dive back into several corona projects that I’ve had to ignore for a while.

BTW, love Corona and I’m a ‘veteran’ (old) VB6/C# developer.

Is this Mr. Maurina that I see on the Geek vids? I’m trying to work my way through all the vids, very cool.

 

well, if you’re using composer, be sure you’re not adding those listeners in the scene:show() method without paying attention to the phases.

scene:show() gets called twice for the phases:

  • will 
  • did

Ah! That’s probably it! I’m still getting up to speed on the diffs between storyboard and composer.

Thanks!

I’ll report back when I check that out.

I’d like to post more about the game and get some input from fellow Coronites. Where/how is the best way to do that?

That was it!

I’ll reread the eventListener() sections of the docs and check the rest of my old code.

Thanks rominggamer!

Sounds like you attached the ‘tap’ listener more than once.  

i.e. This will produce two tap events for one object:

local onTap( self ) print("Tap at time", system.getTimer() ) end local player = display.newCircle( 100, 100, 20 ) player.tap = onTap player:addEventListener("tap") player:addEventListener("tap") -- Now, tapping the listener gives two events (on that object) for every tap.

Also, while tap listeners are very basic, touch listenners has phases (began, moved, ended, …)  if you ignore those then it will seem like you’re getting mulitiple touches when you are just getting the phases of the touch.

I will check that out, but I don’t believe that’s my problem.

I think I’m doing this, based on one of the code examples. Sorry, I don’t have my project in front of my right now.

Also, I believe I’m doing all my eventListener() attachments like this…

local function onTap(e)

end

local player = display.newCircle( 100, 100, 20 )

player:addEventListener(“tap”, onTap)

I just picked this project back up from last year when it was storyboard based and I’m trying to update it to composer. I finally have some time to dive back into several corona projects that I’ve had to ignore for a while.

BTW, love Corona and I’m a ‘veteran’ (old) VB6/C# developer.

Is this Mr. Maurina that I see on the Geek vids? I’m trying to work my way through all the vids, very cool.

 

well, if you’re using composer, be sure you’re not adding those listeners in the scene:show() method without paying attention to the phases.

scene:show() gets called twice for the phases:

  • will 
  • did

Ah! That’s probably it! I’m still getting up to speed on the diffs between storyboard and composer.

Thanks!

I’ll report back when I check that out.

I’d like to post more about the game and get some input from fellow Coronites. Where/how is the best way to do that?

That was it!

I’ll reread the eventListener() sections of the docs and check the rest of my old code.

Thanks rominggamer!