1. Fading
-- not checked for typos -- -- local function onTouch( self, event ) if( event.phase == "ended" ) then self:removeEventListener("touch") transition.to( self, { alpha = 0, time = 1000, onComplete = display.remove } ) end return true end for i = 1, 10 do local tmp = display.newRect( 40 \* i , display.contentCenterY, 30, 30 ) tmp.touch = onTouch tmp:addEventListener("touch") end
2a. Dragging The Long Way
local function onDrag( self, event ) if( event.phase == "began") then self.isFocus = true display.currentStage:setFocus( self, event.id ) self.x0 = self.x self.y0 = self.y self:toFront() elseif( self.isFocus ) then if( event.phase == "ended" ) then self.isFocus = false display.currentStage:setFocus( self, nil ) end local dx = event.x - event.xStart local dy = event.y - event.yStart self.x = self.x0 + dx self.y = self.y0 + dy end return true end for i = 1, 10 do local tmp = display.newRect( 40 \* i , display.contentCenterY, 30, 30 ) tmp.touch = onDrag tmp:addEventListener("touch") end
2b. Dragging the easy way (with SSK2 smartDrag):
for i = 1, 10 do local tmp = display.newRect( 40 \* i , display.contentCenterY, 30, 30 ) ssk.misc.addSmartDrag( tmp, { toFront = true, retval = true } ) end