Hi Magnus,
This is similar to how the “ui” library achieves a rollover effect for buttons.
You should think of this as a transaction. When the phase is “began” then you can start showing the picture. When is “ended” or “cancelled”, you can stop showing the picture. Here’s some stub code that might help. I basically took it straight out of the “ui” library and removed the irrelevant parts:
local function touchHandler( self, event )
local result = true
local phase = event.phase
if “began” == phase then
– START showing picture!!!
– Subsequent touch events will target button even if they are outside the stageBounds of button
display.getCurrentStage():setFocus( self )
self.isFocus = true
elseif self.isFocus 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 “ended” == phase or “cancelled” == phase then
– STOP showing picture!!!
– Allow touch events to be sent normally to the objects they “hit”
display.getCurrentStage():setFocus( nil )
self.isFocus = false
end
end
return result
end
local r = display.newRect( 0, 0, 100, 100 )
r:setFillColor( 255, 255, 255 )
r:addEventListener( “touch”, touchHandler )
[import]uid: 26 topic_id: 739 reply_id: 1483[/import]