Touch on picture, send to front

I wrote a very short test code: when I touch the picture of the car, the ball drawn above it disappears.

 function carTouch( event ) local t = event.target local phase = event.phase if ( phase == "began" ) then local parent = t.parent parent:insert( t ) display.getCurrentStage():setFocus( t ) instance = parent t.isFocus = true elseif ( t.isFocus ) then if ( phase == "moved" ) then elseif ( ( phase == "ended" ) or ( phase == "cancelled" ) ) then print(" t o u c h ! ! ") display.getCurrentStage():setFocus( nil ) t.isFocus = false end end return true end car = display.newImage( "car.png" , 384 , 224 ) car:addEventListener( "touch" , carTouch ) ball = display.newImage( "ball.png" , 108 , 108 ) ball.x = car.x ball.y = car.y

thanks :o

function carTouch( event ) local t = event.target local phase = event.phase if ( phase == "began" ) then local parent = t.parent parent:insert( t ) \<-- " t is already in parent group, no need to insert in again " display.getCurrentStage():setFocus( t ) instance = parent \<-- " why ? " t.isFocus = true elseif ( t.isFocus ) then if ( phase == "moved" ) then elseif ( ( phase == "ended" ) or ( phase == "cancelled" ) ) then print(" t o u c h ! ! ") display.getCurrentStage():setFocus( nil ) t.isFocus = false ball:removeSelf() \<-- " what you want ? " ball=nil end end return true end car = display.newImage( "car.png" , 384 , 224 ) car:addEventListener( "touch" , carTouch ) ball = display.newImage( "ball.png" , 108 , 108 ) ball.x = car.x ball.y = car.y

Thanks, I copied the touch listener from somewhere, I will remove those lines.
In my code I show a car and then a ball above it.
After I tap on the car, the ball is no more visible (the car goes to front), but this is something unexpected.
I would like to keep the ball to front.

ok please suppress 

ball:removeSelf()
ball=nil

If the car goes to front, it will exist a line where it’s write " car:toFront() " or " ball:toBack() " in your code.

perfect! by commenting those 2 lines in listener, nothing disappears!

thank you!

function carTouch( event ) local t = event.target local phase = event.phase if ( phase == "began" ) then local parent = t.parent parent:insert( t ) \<-- " t is already in parent group, no need to insert in again " display.getCurrentStage():setFocus( t ) instance = parent \<-- " why ? " t.isFocus = true elseif ( t.isFocus ) then if ( phase == "moved" ) then elseif ( ( phase == "ended" ) or ( phase == "cancelled" ) ) then print(" t o u c h ! ! ") display.getCurrentStage():setFocus( nil ) t.isFocus = false ball:removeSelf() \<-- " what you want ? " ball=nil end end return true end car = display.newImage( "car.png" , 384 , 224 ) car:addEventListener( "touch" , carTouch ) ball = display.newImage( "ball.png" , 108 , 108 ) ball.x = car.x ball.y = car.y

Thanks, I copied the touch listener from somewhere, I will remove those lines.
In my code I show a car and then a ball above it.
After I tap on the car, the ball is no more visible (the car goes to front), but this is something unexpected.
I would like to keep the ball to front.

ok please suppress 

ball:removeSelf()
ball=nil

If the car goes to front, it will exist a line where it’s write " car:toFront() " or " ball:toBack() " in your code.

perfect! by commenting those 2 lines in listener, nothing disappears!

thank you!