Moving objects around a box

Hi everyone,

What I’m trying to do is:

  • I got 8 cups that I want to move around a rectangle

  • Created a table with 50 locations where the cup has to move (segments table)

  • Once the first cup is at segment 5, i display the next one at segment one, and start to move it, and so on.

When using 1 cup, it works perfectly fine. When using 2 or more, for some reason the transitions speed up, and they go nuts.

Anyone?

 currSegment = 1 cupNumber = 1 SetRotation = 0 local cups = {} for i=1,8 do cups[i] = display.newImage("cup.png") cups[i].x = segMents[1].x cups[i].y = segMents[1].y cups[i].currSegment = 1 cups[i].cupNumber = i cups[i].setRotation = 0 physics.addBody( cups[i], "static", physicsData:get("cup") ) cups[i].isVisible = false end function nextSegment() for num=1,8 do if cups[num].isVisible == true then --- Delete transition cups[cupNumber].trans = nil --- Advance to next segment cups[num].currSegment = cups[num].currSegment + 1 -- If cup between segment 37 and 44, rotate if cups[num].currSegment \> 37 and cups[num].currSegment \< 44 then cups[num].setRotation = cups[num].setRotation + 60 end --- Cup at segment 44, reset rotation if cups[num].currSegment == 44 then cups[num].rotation = 0 cups[num].setRotation = 0 end --- Cup at last segment, reset to 1 if cups[num].currSegment == 47 then cups[num].currSegment = 1 end --- Transition to next segment MoveCup(num,cups[num].currSegment) else --- visible = false --- Previous cup at segment 5, make next one visible and move it if cups[num-1].currSegment == 5 then --- Transition to next segment MoveCup(num,cups[num].currSegment) end end end end function MoveCup(cupNumber, segment) print("MoveCup: ",cupNumber,segment) --print("Segment: ",segment) cups[cupNumber].isVisible = true cups[cupNumber].trans = transition.to( cups[cupNumber], {x=segMents[segment].x,y=segMents[segment].y,rotation=cups[cupNumber].setRotation,onComplete=nextSegment} ) end MoveCup(cupNumber,currSegment)