I’ve made some progress though I know it’s not the right way and it’s not working like I’d hoped so If anyone can give me some advice what to do with my swapping/rearrange of the tiles.
thanks.
local tileArray = {} local tempArray = {} local colors = {"Green", "Red", "Orange", "Blue", "White"} -- tile id's local letters = {"G", "R", "O", "B", "W"} -- if the user is colorblind -- Just a rect to see where the tiles transition to, not of importance. local stripe = display.newRect(0, 170, display.contentWidth, 60) stripe:setFillColor(100, 1, 22, 255) function touchListener(event) local phase = event.phase local target = event.target if phase == "began" then print(" Touch Tile in Phase : ", phase) display.getCurrentStage():setFocus(target) target.markX = target.x target.markY = target.y elseif phase == "moved" then print(" Touch Tile in Phase : ", phase) target.x = event.x - event.xStart + target.markX target.y = event.y - event.yStart + target.markY elseif phase == "ended" or phase == "cancelled" then print(" Touch Tile in Phase : ", phase, target.color) display.getCurrentStage():setFocus(nil) transition.to(target, { x = 160, y = 200, time = 250, delay = 0, alpha = 1.0, transition = easing.inExpo, onComplete = function() tempArray[#tempArray + 1] = target target:removeEventListener("touch", touchListener) end }) for i = 1, #tempArray do local tempTile = tempArray[#tempArray] tempTile.x = 50 + (i - 1) \* 55 tempTile:addEventListener("touch", reArrangeListener) end end return true end for i = 1, 5 do tileArray[#tileArray + 1] = display.newRect(0, 0, 50, 50) local tile = tileArray[#tileArray] tile.x = 50 + (i - 1) \* 55 tile.y = display.contentHeight - 100 tile.color = colors[i] tile.letter = letters[i] tile:setFillColor(math.random(0, 255), math.random(0, 255), math.random(0, 255), 255) tile:addEventListener("touch", touchListener) end function reArrangeListener(event) local phase = event.phase local target = event.target target:toFront() if phase == "began" then print(" Touch Tile in Phase : ", phase) display.getCurrentStage():setFocus(target) target.markX = target.x transition.to(target, { time = 50, delay = 0, xScale = 1.25, yScale = 1.25, transition = easing.inExpo, onComplete = function() end}) elseif phase == "moved" then print(" Touch Tile in Phase : ", phase) target.x = event.x - event.xStart + target.markX elseif phase == "ended" or phase == "cancelled" then print(" Touch Tile in Phase : ", phase) display.getCurrentStage():setFocus(nil) transition.to(target, { time = 50, delay = 0, xScale = 1.0, yScale = 1.0, transition = easing.inExpo, onComplete = function() end}) end return true end