I’m trying to implement a reorder of game tiles. e.g. bit like a scrabble tile deck.
Can get drag-n-drop working fine. But want to transition adjacent tile left or right when dragging across the deck over existing tiles. I understand transitions. Just need to get the
Have attempted various things: custom “enter/leave” events for specific zones but still end up with what seems to be a complex approach and tiles jitter about.
Does anybody have a simple suggestion or done similar. i’ve put a basic sample together to show what im after. Hopefully someone can enlighten me,
–sample code
local tiles={}
local w=40
local h=40
–display.setDrawMode(“wireframe”,false)
local tileMove = function(self,e)
local t = e.target
print(“phase:”,e.phase)
if “began” == e.phase then
print("picked up index: ",t.index)
– Make target the top-most object
--local parent = t.parent
--parent:insert( t )
display.getCurrentStage():setFocus( t, e.id )
t.isFocus = true
t:toFront()
– Store initial position
t.x0 = e.x - t.x
t.xScale=1.35;t.yScale=1.35 --scale on begin drag
elseif “moved” == e.phase then
t.x = e.x - t.x0
elseif “ended” == e.phase then
t.xScale=1;t.yScale=1 – revert scale
display.getCurrentStage():setFocus( t, nil )
t.isFocus = false
elseif “cancelled” == e.phase then
t.xScale=1;t.yScale=1 – revert scale
display.getCurrentStage():setFocus( t, nil )
t.isFocus = false
end
return true
end
for i=1,7 do
tiles[i] = display.newRoundedRect(0, 0, w, h,4)
tiles[i]:setFillColor(0,0,0)
tiles[i].stroke={0,1,0}
tiles[i].strokeWidth = 2
tiles[i].x=i*w
tiles[i].y=100
tiles[i].anchorX=0.5
tiles[i].anchorx=0.5
tiles[i].index=i
tiles[i].touch=tileMove
tiles[i]:addEventListener(“touch”,tiles[i])
end