Hi guys!
I have 3 text lines for which I have set a touch event listener.
I would like that when :
- When the touch begins, the touched object scales up (2x)
- When it is no longer touched, it reverts to its previous state (1x)
- When in a single touch + drag over the lines, only the currently selected object is scaled
I tried the following, but I’m unsure if it the best route to accomplish this (I don’t like it…)
I’d appreciate any an all insight, help, feedback!
Thanks!
S.
[code]
local currentlyTouchedObject
local function onOptionTouched( self, event )
if currentlyTouchedObject == nil then
currentlyTouchedObject = event.target
elseif currentlyTouchedObject ~= event.target then
print( “NOT EQUAL” )
currentlyTouchedObject:scale(0.5, 0.5)
currentlyTouchedObject = event.target
event.target:scale(2.0, 2.0)
end
if event.phase == “began” then
event.target:scale(2.0, 2.0)
elseif event.phase == “ended” or event.phase == “cancelled” then
event.target:scale(0.5, 0.5)
elseif event.phase == “moved” then
– return false
end
return true
end
…
local option1 = display.newText( “Option 1”, 0, 0, native.systemFont, 18 )
option1:setReferencePoint(display.TopLeftReferencePoint)
option1.x = actor.contentWidth
option1.y = display.contentHeight - actor.contentHeight
option1.tag = 1
option1.touch = onOptionTouched
option1:addEventListener( “touch”, option1)
local option2 = display.newText( “Option 2”, 0, 0, native.systemFont, 18 )
option2:setReferencePoint(display.TopLeftReferencePoint)
option2.x = actor.contentWidth + 40
option2.y = display.contentHeight - actor.contentHeight + 40
option2.tag = 2
option2.touch = onOptionTouched
option2:addEventListener( “touch”, option2)
local option3 = display.newText( “Option 3”, 0, 0, native.systemFont, 18 )
option3:setReferencePoint(display.TopLeftReferencePoint)
option3.x = actor.contentWidth + 80
option3.y = display.contentHeight - actor.contentHeight + 80
option3.tag = 3
option3.touch = onOptionTouched
option3:addEventListener( “touch”, option3)
…
[/code] [import]uid: 133444 topic_id: 30286 reply_id: 330286[/import]
