Scaling buttons as touch goes over.

Hi all,

I am trying to have buttons scale down as my finger goes over them but have them go back up when my finger stops going over them. I need this to work on all the buttons on the same touch (so in other words you can drag your finger over all the buttons and they all scale up as the finger is over them and down as it leaves them). Also whatever button you remove you finger from also needs to be trackable. Does anyone have any ideas?

Thanks,

Chris [import]uid: 126017 topic_id: 28626 reply_id: 328626[/import]

I guess thats impossible. There is no event like “mouseover” in iOS but you can have these effects in the begin phase of a button press.

Joakim [import]uid: 81188 topic_id: 28626 reply_id: 115444[/import]

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]