[Resolved] transition in a for loop

The for loop gives the coordinates where to move the marker (a path), only the transition goes directly to the last coordinates.
I tried to make a performwithDelay() but i’m afraid i doesn’t handle that right

the xto and yto gives the right coordinates (before the function), but the xto in the function gives only the last coordinates (so this function is called after the for loop is completed.

so what i want is: move the marker from coordinate to coordinate and not (as now) from the begining direcly (linear) to the last coordinates. (the loop must not loop again until the transition is over)

thanks

[lua]animate = function(event)
local beginx = 1;
local beginy = 1;
local endx = 10
local endy = 10

path = CalcPath(CalcMoves(board, beginx, beginy, endx, endy))

local marker = display.newCircle(0,0, 8)
marker:setFillColor(255, 174, 0)

for i = 1, table.getn(path) do
newX = path[i].x
newY = path[i].y

xto=(newX*32-16)
yto=(newY*32-16)

print(yto)

local function mover()
transition.to(marker, {time=100, x=xto, y=yto });
print(xto);
end
timer.performWithDelay(i, mover, 1)

end
end[/lua] [import]uid: 18622 topic_id: 29361 reply_id: 329361[/import]

I think changing your transition to this should do it:

[lua] transition.to(marker, {delay = 100*(i-1),time=100, x=xto, y=yto });
print(xto);[/lua] [import]uid: 93133 topic_id: 29361 reply_id: 117986[/import]

Thanks for the fast reply!
it works! :slight_smile:

only there are two markers ‘walking’ after each other (the for loop is giving the coordinates twice) (i’m trying to fix that now).

thanks again for answering! [import]uid: 18622 topic_id: 29361 reply_id: 117987[/import]

alright that was easy: it was called with an touch event (so the function was called a lot of times).

thanks again! you made my day :wink: [import]uid: 18622 topic_id: 29361 reply_id: 117989[/import]