Hi, I am trying to show a new picture with the event.phase.
If “moved”== phase works but I want a new picture to show as long as I am holding the button down.
I tried “stationary” == phase but it didn´t work.
Magnus
[import]uid: 5717 topic_id: 739 reply_id: 300739[/import]
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
I have an array of pictures and I want to show a new picture in the array (next picture, it is like an animation) as long as I hold the button down but I can´t figure it out.
Magnus [import]uid: 5717 topic_id: 739 reply_id: 1498[/import]
Something like this?
local function pictureRotate(event)
–Rotate action goes in here
end
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
–Start rotate function
Runtime:addEventListener(“enterFrame”, pictureRotate)
if “ended” == phase or “cancelled” == phase then
– STOP showing picture!!!
–End rotate function
Runtime:removeEventListener(“enterFrame”, pictureRotate)
– 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 ) [import]uid: 5708 topic_id: 739 reply_id: 1503[/import]