Modifying a transition in process

Sorry if this is a newb question.

I am making a game where several events can move objects around, and I’m animating those moves with transition.to and transition.moveby. The thing I’ve discovered though is that if you trigger a transition on an object that has an existing transition in progress, the two aren’t somehow gracefully merged, Corona instead does some erratic things where the object can move to unpredictable places depending on timing and some move events can get overridden.

Ideally I’d use only moveby and the net destination and timing would just get worked out. There also doesn’t seem to be a way to modify a transition that is in process.

I looked into using onComplete to chain animations together myself, but I can’t seem to find a way to check if an object has an existing transition.

Any suggestions?

euph, 

Can you post some code? That would give people a better idea what you are trying to achieve. Objects in transition can’t have a second transition applied to them until the first one is finished, else you end up with erratic movement. 

Jim

I agree, that I’d like to see some code, but wanted to point out.  You can have as many active transitions on an object that you want, BUT if two or more transitions are modifying the same value you’ll get weird behavior:

Ex 1 - WEIRD:

local obj = display.newCircle( 100, 100, 10 ) transition.to( obj, { x = 200, time = 1000 } ) transition.to( obj, { x = 100, time = 1000 } )

Ex 2 - Just fine:

local obj = display.newCircle( 100, 100, 10 ) transition.to( obj, { x = 200, time = 1000 } ) transition.to( obj, { y = 200, time = 1000 } )

Basically, the first sample has two independent bits of code modifying x to be some value every simulation cycle.  The last to execute will win the battle.

Thanks for clarifying that point Ed. Keep up the great work with Corona Geek!

Thank you very much for the excellent answers. This did answer my question. I’ll try to clarify the problem, and share how I solved it so it helps others.

I’m afraid there’s a lot of code I would have to post so I’ll do my best to summarize… it is a tetris-esque game with a 2D array of tiles. Lots of events can cause tiles to move to different locations, based on timers, user input, or cascading effects from user input or timer.

The issue is that many of these events would move tiles by doing a transition.moveby, applying changes to both the X and Y properties. I was hoping that like some other animation systems I could feed in multiple simultaneous transitions and tiles would end up at the right place, but like both of you surmised it doesn’t work that way. Multiple transitions on the same object are not aware of each other and will fight instead of merging animations as they do on some other platforms.

The solution: for the affected tiles I tracked animation state on each object with a queue of X/Y changes to be applied, and an animation would be triggered or later executed as needed:

function moveRectBy(rect, targetX, targetY) if rect.animationQueueLength \> 0 then table.insert(rect.moveQueue, { x = targetX, y = targetY}) else rect.currentTransition = transition.moveBy(rect, { time = 500, x = targetX, y = targetY, transition = easing.outQuart, onComplete = moveRectByNext}) end rect.animationQueueLength = rect.animationQueueLength + 1 -- animationQueueLength includes animations in progress as well as those in the queue table end function moveRectByNext(obj) obj.animationQueueLength = obj.animationQueueLength - 1 if obj.animationQueueLength \> 0 then local nextMove = table.remove(obj.moveQueue, 1) obj.currentTransition = transition.moveBy(obj, { time = 500, x = nextMove.x, y = nextMove.y, transition = easing.outQuart, onComplete = moveRectByNext}) else obj.currentTransition = nil end end

(I have been in project management roles for a long time and this is my first time coding in years… so I am a bit embarrassed of my garbage spaghetti code. Hope it’s helpful to someone else.)

euph, 

Can you post some code? That would give people a better idea what you are trying to achieve. Objects in transition can’t have a second transition applied to them until the first one is finished, else you end up with erratic movement. 

Jim

I agree, that I’d like to see some code, but wanted to point out.  You can have as many active transitions on an object that you want, BUT if two or more transitions are modifying the same value you’ll get weird behavior:

Ex 1 - WEIRD:

local obj = display.newCircle( 100, 100, 10 ) transition.to( obj, { x = 200, time = 1000 } ) transition.to( obj, { x = 100, time = 1000 } )

Ex 2 - Just fine:

local obj = display.newCircle( 100, 100, 10 ) transition.to( obj, { x = 200, time = 1000 } ) transition.to( obj, { y = 200, time = 1000 } )

Basically, the first sample has two independent bits of code modifying x to be some value every simulation cycle.  The last to execute will win the battle.

Thanks for clarifying that point Ed. Keep up the great work with Corona Geek!

Thank you very much for the excellent answers. This did answer my question. I’ll try to clarify the problem, and share how I solved it so it helps others.

I’m afraid there’s a lot of code I would have to post so I’ll do my best to summarize… it is a tetris-esque game with a 2D array of tiles. Lots of events can cause tiles to move to different locations, based on timers, user input, or cascading effects from user input or timer.

The issue is that many of these events would move tiles by doing a transition.moveby, applying changes to both the X and Y properties. I was hoping that like some other animation systems I could feed in multiple simultaneous transitions and tiles would end up at the right place, but like both of you surmised it doesn’t work that way. Multiple transitions on the same object are not aware of each other and will fight instead of merging animations as they do on some other platforms.

The solution: for the affected tiles I tracked animation state on each object with a queue of X/Y changes to be applied, and an animation would be triggered or later executed as needed:

function moveRectBy(rect, targetX, targetY) if rect.animationQueueLength \> 0 then table.insert(rect.moveQueue, { x = targetX, y = targetY}) else rect.currentTransition = transition.moveBy(rect, { time = 500, x = targetX, y = targetY, transition = easing.outQuart, onComplete = moveRectByNext}) end rect.animationQueueLength = rect.animationQueueLength + 1 -- animationQueueLength includes animations in progress as well as those in the queue table end function moveRectByNext(obj) obj.animationQueueLength = obj.animationQueueLength - 1 if obj.animationQueueLength \> 0 then local nextMove = table.remove(obj.moveQueue, 1) obj.currentTransition = transition.moveBy(obj, { time = 500, x = nextMove.x, y = nextMove.y, transition = easing.outQuart, onComplete = moveRectByNext}) else obj.currentTransition = nil end end

(I have been in project management roles for a long time and this is my first time coding in years… so I am a bit embarrassed of my garbage spaghetti code. Hope it’s helpful to someone else.)