Tap producing two output and cant toBack() background

I have two problems in executing this code. First when i tap the chick move, but the output at console showing it just jump twice, which i want it to jump one time since i just tap one. Second the lanes are in array so that i can control the movement of cars and the chick, but it overlaps everything when I try turn-back it just doing for the last lane which is lane 3. I am sorry for the lack of skills and sloppy codes and thanks in advance for your help.

To make it easier i include all things that needed 

main.lua

game2.lua

chick.png

road.png

lane.png

Primary issue: You may not realize this, but show and hide have two phase: “will” and “did”.  So you’re adding the event listeners twice.

Secondary issues: I found a smattering of bad practices and less advanced practices.  I cleaned those all up.  For example, you were wrongly calculating the edges of the screen and it would not have worked on all screens. 

Download this:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/04/chicken.zip

and compare:

  • orig_chicken/ - Your original sample.
  • chicken/ - My changes to main.lua and game2.lua

-Ed

Tip: I noticed a decided lack of spaces in your code.  I suggest adding more spaces to improve legibility.

Ex:

This

transition.to(obj,{x=100,y=150,time=1500,transition=easing.outBack})

is better (IMHO) like this:

transition.to( obj, { x = 100, y = 150, time = 1500, transition = easing.outBack } )

It also helps ensure any user who edits this can click and select bits of code cleanly regardless of OS and editor they use.

White-space is almost universally understood by editors to mean new-string.  i.e. In some cases double clicking ‘transition’ in the first sample might end up selecting ‘transition=easing.outBack’.  

Primary issue: You may not realize this, but show and hide have two phase: “will” and “did”.  So you’re adding the event listeners twice.

Secondary issues: I found a smattering of bad practices and less advanced practices.  I cleaned those all up.  For example, you were wrongly calculating the edges of the screen and it would not have worked on all screens. 

Download this:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/04/chicken.zip

and compare:

  • orig_chicken/ - Your original sample.
  • chicken/ - My changes to main.lua and game2.lua

-Ed

Tip: I noticed a decided lack of spaces in your code.  I suggest adding more spaces to improve legibility.

Ex:

This

transition.to(obj,{x=100,y=150,time=1500,transition=easing.outBack})

is better (IMHO) like this:

transition.to( obj, { x = 100, y = 150, time = 1500, transition = easing.outBack } )

It also helps ensure any user who edits this can click and select bits of code cleanly regardless of OS and editor they use.

White-space is almost universally understood by editors to mean new-string.  i.e. In some cases double clicking ‘transition’ in the first sample might end up selecting ‘transition=easing.outBack’.