rect = {} local function touch(e) local id = e.target.id local id2 = e.target.id2 if e.phase == "began" then elseif e.phase == "moved" then if e.y \<= rect[id][id2].contentBounds.yMin --or e.y \>= rect[id][id2].contentBounds.yMax then rect[id][id2]:setFillColor(1,1,1) rect[id][id2].alpha = 0.5 end end end local function touch2(e) local id = e.target.id local id2 = e.target.id2 if e.phase== "began" then elseif e.phase == "moved" then rect[id][id2]:setFillColor(1,0,0) rect[id][id2].alpha = 1 rect[id][id2]:addEventListener("touch",touch) end end for i = 1 ,1 do rect[i] ={} for j = 1 , 5 do rect[i][j] = display.newRect( 100, 100, 50,50 ) rect[i][j].x = i \*55 +150 rect[i][j].y = j\*55 rect[i][j].id = i rect[i][j].id2 = j rect[i][j]:setFillColor( 1, 1, 1 ) rect[i][j].alpha = 0.5 rect[i][j]:addEventListener("touch",touch2) end end
When I touch and move the grid will change to red color , then how to change the grid color to white when I move to the opposite direction ?