transition.moveTo how to tell if an object is still in the process of the transition?

I have multiple object then when touched, they trigger transition.moveTo in order to move to a specific location.

I want something to trigger once the object reaches that end location, so I am using the param onComplete within my transition.moveTo.

The issue is that when one object finishes the transition, it triggers the onComplete for all of the objects even if they have not reached the end point.

I was thinking that I need to edit my onComplete function and put a condition that can see if the object is still moving or not.

This leads me to my question. when an object is transitioning, is there a linear velocity that is being activated in the background?

I am struggling with finding something to tell if an object transition is still in process.

Sounds like you’re implementing onComplete incorrectly.  Try this:

local function onComplete( self ) print( self.name, "done at" , system.getTimer() ) end local obj1 = display.newCircle( 10, 10, 10 ) local obj2 = display.newCircle( 10, 10, 10 ) obj1.name = "bob" obj1.onComplete = onComplete obj2.name = "sue" obj2.onComplete = onComplete transition.to( obj1, { x = 100, time = 1500, onComplete = obj1 } ) transition.to( obj2, { x = 200, time = 1750, onComplete = obj2 } )

Oh, and lots of questions for one post usually ends up with some questions not answered, but

No, there is no velocity.  Transitions do no use the physics system, thus no velocity.  You need to calculate that yourself.  I’d use an enterFrame listener per object to track the object’s velocity.

ex: (may contain typos)

-- same code as above, plus this local function enterFrame( self ) local curTime = system.getTimer() if( self.lx ~= nil ) then local dx = self.x - self.lx local dy = self.y = self.ly local dt = curTime - self.lt if( dt \> 0 ) then local vx = dx/dt local vy = dy/dt self.velocity = 1000 \* math.sqrt( vx \* vx + vy \* vy ) -- in (design) pixels-per-second else self.velocity = 0 end else self.velocity = 0 end self.lx = self.x self.ly = self.y self.lt = curTime end obj1.enterFrame = enterFrame obj2.enterFrame = enterFrame Runtime:addEventListener("enterFrame", obj1) Runtime:addEventListener("enterFrame", obj2)

Now you can print velocity of obj1 or obj2 as:

print( obj1.name, " moving at ", obj1.velocity, " pixels-per-second " )

I think the issue with mine is that my transition is within a function that is activated by touching one of the objects. Since the function just plugs in the object I touch its messing it up when I touch a new object without the fist one stopping 

Note: Someone check my math, I may need that 1000 mult on vx, vy instead.  

That wouldn’t make a difference.  

I think the problem is that you’re probably not using a table listener, but a function listener instead.  Thus the function has no idea what object just completed.

In my example, the two objects use a single function as a table listener so that code always references the right object.

That makes sense. I’ll see what I can do for implementing your idea above. I appreciate the help

Note: I don’t use function listeners for onComplete often, but I’m pretty sure the object is passed as the first argument, so this should work too:

local function onComplete( self ) print( self.name, "done at" , system.getTimer() ) end local obj1 = display.newCircle( 10, 10, 10 ) local obj2 = display.newCircle( 10, 10, 10 ) obj1.name = "bob" obj2.name = "sue" transition.to( obj1, { x = 100, time = 1500, onComplete = onComplete } ) transition.to( obj2, { x = 200, time = 1750, onComplete = onComplete } )

The main thing you want to avoid is directly referring to an object in the listener:

local function onComplete()    print( obj1.name, "done at" , system.getTimer() ) end

, while this has its uses, it can cause you troubles if you accidently refer to the wrong object.

Anyways, I hope you get it worked out.

Sounds like you’re implementing onComplete incorrectly.  Try this:

local function onComplete( self ) print( self.name, "done at" , system.getTimer() ) end local obj1 = display.newCircle( 10, 10, 10 ) local obj2 = display.newCircle( 10, 10, 10 ) obj1.name = "bob" obj1.onComplete = onComplete obj2.name = "sue" obj2.onComplete = onComplete transition.to( obj1, { x = 100, time = 1500, onComplete = obj1 } ) transition.to( obj2, { x = 200, time = 1750, onComplete = obj2 } )

Oh, and lots of questions for one post usually ends up with some questions not answered, but

No, there is no velocity.  Transitions do no use the physics system, thus no velocity.  You need to calculate that yourself.  I’d use an enterFrame listener per object to track the object’s velocity.

ex: (may contain typos)

-- same code as above, plus this local function enterFrame( self ) local curTime = system.getTimer() if( self.lx ~= nil ) then local dx = self.x - self.lx local dy = self.y = self.ly local dt = curTime - self.lt if( dt \> 0 ) then local vx = dx/dt local vy = dy/dt self.velocity = 1000 \* math.sqrt( vx \* vx + vy \* vy ) -- in (design) pixels-per-second else self.velocity = 0 end else self.velocity = 0 end self.lx = self.x self.ly = self.y self.lt = curTime end obj1.enterFrame = enterFrame obj2.enterFrame = enterFrame Runtime:addEventListener("enterFrame", obj1) Runtime:addEventListener("enterFrame", obj2)

Now you can print velocity of obj1 or obj2 as:

print( obj1.name, " moving at ", obj1.velocity, " pixels-per-second " )

I think the issue with mine is that my transition is within a function that is activated by touching one of the objects. Since the function just plugs in the object I touch its messing it up when I touch a new object without the fist one stopping 

Note: Someone check my math, I may need that 1000 mult on vx, vy instead.  

That wouldn’t make a difference.  

I think the problem is that you’re probably not using a table listener, but a function listener instead.  Thus the function has no idea what object just completed.

In my example, the two objects use a single function as a table listener so that code always references the right object.

That makes sense. I’ll see what I can do for implementing your idea above. I appreciate the help

Note: I don’t use function listeners for onComplete often, but I’m pretty sure the object is passed as the first argument, so this should work too:

local function onComplete( self ) print( self.name, "done at" , system.getTimer() ) end local obj1 = display.newCircle( 10, 10, 10 ) local obj2 = display.newCircle( 10, 10, 10 ) obj1.name = "bob" obj2.name = "sue" transition.to( obj1, { x = 100, time = 1500, onComplete = onComplete } ) transition.to( obj2, { x = 200, time = 1750, onComplete = onComplete } )

The main thing you want to avoid is directly referring to an object in the listener:

local function onComplete()    print( obj1.name, "done at" , system.getTimer() ) end

, while this has its uses, it can cause you troubles if you accidently refer to the wrong object.

Anyways, I hope you get it worked out.