onUpdate for Transitions

This has been asked before, but Corona  really needs an onUpdate listener to the transition library. I can’t imagine that this would be hard (it’s been done several times by third-party transition libraries), and without it, using Corona’s native transitions is difficult with things that need instant-updates for value changes (have to use metatables and .__newindex).

  • Caleb

+1

Just for clarity, “onUpdate” of what? Every frame of the transition is an “update”? What exactly constitutes an update to a transition? I’m sure it’s obvious enough when I hear it, but please clarify what you’re thinking and what a sample code bit may look like.

Thanks,

Brent

Hi Brent,

Well the one for AS3 was on screen update.  That’s what I was referring to.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/transitions/Tween.html#event:motionChange

Hi @develephant, Caleb,

How do you envision this working in Corona/Lua? Does an “update” occur when you assign a new transition to the same object, perhaps by referencing its ID, name, tag, etc.?

The AS3 one says:

“Indicates that the Tween has changed and the screen has been updated.”

But I’m not fully getting what “tween has changed” means, and by what method or action. If you can clarify how you’d like this to work in Corona/Lua, we may be able to implement it.

Thanks,

Brent

I’m thinking of onUpdate as each time the object gets “ticked” (gets called directly after the object is moved/alpha-ed/scaled/whatever). I can’t use enterFrame listeners for it because by the time the next frame comes along, the object has already been drawn.

It would be added the exact same way the current transition callback functions are:

[lua]

transition.to(object, {alpha = 0, time = 300, onComplete = function() print(“completed”) end, onUpdate = function() print(“updated”) end})

[/lua]

  • Caleb

+1

Just for clarity, “onUpdate” of what? Every frame of the transition is an “update”? What exactly constitutes an update to a transition? I’m sure it’s obvious enough when I hear it, but please clarify what you’re thinking and what a sample code bit may look like.

Thanks,

Brent

Hi Brent,

Well the one for AS3 was on screen update.  That’s what I was referring to.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/transitions/Tween.html#event:motionChange

Hi @develephant, Caleb,

How do you envision this working in Corona/Lua? Does an “update” occur when you assign a new transition to the same object, perhaps by referencing its ID, name, tag, etc.?

The AS3 one says:

“Indicates that the Tween has changed and the screen has been updated.”

But I’m not fully getting what “tween has changed” means, and by what method or action. If you can clarify how you’d like this to work in Corona/Lua, we may be able to implement it.

Thanks,

Brent

Any progress on this?

  • C

Why can’t an enterFrame listener be used for this?  If the transition is running, i.e. onComplete hasn’t fired, then it has changed since the last frame, so you should be able to grab any object variables (x, y, alpha, etc) in an enterFrame listener.   Basically an onUpdate is going to add an enterFrame listener for you.

Has anyone asked for this on the feedback site (http://feedback.coronalabs.com) and voted it up?

Rob

Because the object gets drawn before the next enterFrame event occurs. Thus, when a function updates the appearance of an object according to a transitioned value, there’s a small “tick” as the object is first updated by the transition and then updated by the function.

Specifically, I’m thinking of the Dusk Engine and camera scaling. When you use map:scale(1.05, 1.05) every frame and then directly after (before the next frame comes) use map.updateView() (which sets the map center to the correct place), everything’s fine. But if you use transition.to(map, {xScale = 2, yScale = 2}) and then map.updateView() in an enterFrame listener, the map “jitters” because the map is first scaled, and then, next frame, updated.

I have not posted it on the feedback; will do that directly.

  • Caleb

I’m thinking of onUpdate as each time the object gets “ticked” (gets called directly after the object is moved/alpha-ed/scaled/whatever). I can’t use enterFrame listeners for it because by the time the next frame comes along, the object has already been drawn.

It would be added the exact same way the current transition callback functions are:

[lua]

transition.to(object, {alpha = 0, time = 300, onComplete = function() print(“completed”) end, onUpdate = function() print(“updated”) end})

[/lua]

  • Caleb

Was just searching for this feature and found this post. I would like a transition update.

A work around might be to add an enterFrame event and remove it onComplete.

Any progress on this?

  • C

Why can’t an enterFrame listener be used for this?  If the transition is running, i.e. onComplete hasn’t fired, then it has changed since the last frame, so you should be able to grab any object variables (x, y, alpha, etc) in an enterFrame listener.   Basically an onUpdate is going to add an enterFrame listener for you.

Has anyone asked for this on the feedback site (http://feedback.coronalabs.com) and voted it up?

Rob

Because the object gets drawn before the next enterFrame event occurs. Thus, when a function updates the appearance of an object according to a transitioned value, there’s a small “tick” as the object is first updated by the transition and then updated by the function.

Specifically, I’m thinking of the Dusk Engine and camera scaling. When you use map:scale(1.05, 1.05) every frame and then directly after (before the next frame comes) use map.updateView() (which sets the map center to the correct place), everything’s fine. But if you use transition.to(map, {xScale = 2, yScale = 2}) and then map.updateView() in an enterFrame listener, the map “jitters” because the map is first scaled, and then, next frame, updated.

I have not posted it on the feedback; will do that directly.

  • Caleb

Was just searching for this feature and found this post. I would like a transition update.

A work around might be to add an enterFrame event and remove it onComplete.

Rob’s suggestion does work (and this is how I implement onUpdate for my apps) but it’s quite cumbersome having to manage adding and removing event listeners in code for something as simple as this, especially when you have multiple tweens requiring onUpdate.

Most modern tween engines (JQuery, Greensock, GTween) support onUpdate/step and long ago even Adobe’s in built AS2 tween API supported this so why can’t the Corona SDK?

Here’s the link to Caleb’s feature request if anyone else wants to up vote this:

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/5300531-onupdate