2
votes

I am working on a game using Corona SDK , I have number of balls to display in game . i have implemented TouchListener to all of ball objects enter image description here.

Code is here

local function ballTouchEvent(e)

    local touchedBall = e.target
    local phase = e.phase

    if phase == "began" then

        log("Touch began Phase")    

    elseif phase == "moved" then

         log("Moved Phase")

    elseif phase == "ended" or phase == "cancelled" then

        log("Ended Phase")  

    end

    return true
end

ball:addEventListener("touch",ballTouchEvent)

I want to implement some functionality when user touches on any of shown ball and moves his touch to white background (Place having no Ball) . Can any one guide me how to implement this ? Thanks in advance

2
Are you using any group to display all of YOUR balls ? if yes then you can add touch listener to that group to solve your problem - Arslan Asim
May i need to have that group on complete screen ? - Salman Nazir

2 Answers

1
votes

Implement a React behind all of balls and implement click listener to that react. SO that when user leave the touch on white space, the ended phase of react listener will be called and you can put your implementation there what you want to do .

function scene:create( event )
        sceneGroup = self.view
        local rect = display.newRect(centerX, centerY, constants.screenWidth, constants.screenHeight)       
        -- rect:setFillColor( 0.0 )
        rect.name = "background"
        rect:addEventListener("touch",backTouchEvent)
sceneGroup:insert( rect )
end
0
votes

You can add a group and then handle touch listener and do your work in group's end touch call.

Please visit the following link

Touch Event detection issue