The key here is knowing when the touch is within the button’s bounds…
local isWithinBounds = bounds.xMin <= x and bounds.xMax >= x and bounds.yMin <= y and bounds.yMax >= y
Try this function:
[code]
local function onButtonTouch(event)
local phase = event.phase
local self = event.target
if(phase == “began”) then
display.getCurrentStage():setFocus( self )
self.isFocus = true
elseif(self.isFocus) then
if(phase == “moved”) then
local bounds = self.stageBounds
local x,y = event.x,event.y
local isWithinBounds =
bounds.xMin <= x and bounds.xMax >= x and bounds.yMin <= y and bounds.yMax >= y
if(not isWithinBounds) then
self.xScale = 1
self.yScale = 1
self.click = false
else
self.xScale = 0.5
self.yScale = 0.5
self.click = true
end
elseif(phase == “ended” ) then
– Touch ended, but outside the buttons bounds
if(not self.click) then
display.getCurrentStage():setFocus( nil )
self.isFocus = false
return
end
self.xScale = 1
self.yScale = 1
self.click = nil
display.getCurrentStage():setFocus( nil )
self.isFocus = false
end
end
end
[code] [import]uid: 54030 topic_id: 28626 reply_id: 115473[/import]