Salman Nazir
Salman Nazir

Reputation: 2837

Corona SDK - How to implement Object Cancelled touch

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

Upvotes: 2

Views: 102

Answers (2)

user6032845
user6032845

Reputation:

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

Upvotes: 1

Hunain
Hunain

Reputation: 396

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

Upvotes: 0

Related Questions