Solution to transitions not working on device

This looks like a common problem:

http://developer.anscamobile.com/forum/2011/04/15/director-transitions-android-dont-work

See my test apps in this thread:

http://developer.anscamobile.com/forum/2011/05/03/director-not-transitioning-iphone-vs-simulator

Turns out Director is sluggish with relatively heavy scenes. It probably depends on device. The more graphics you have in the scene you are transitioning to, the higher probability you won’t see a smooth transition on the device (or any transition at all).

Also, it looks like some transitions work better than the other, e.g. “crossfade” appears to work better than “moveFromRight”. Maybe cause it uses only one “transition.to”, while “moveFromRight” uses two.

SOLUTION:

Adding a pause after the “loadScene” call inside Director’s “changeScene” method solves the problem.

[lua]if effect == “moveFromRight” then

nextView.x = display.contentWidth
nextView.y = 0

loadScene (newScene)

– Don’t call these right away!

– showFx = transition.to ( nextView, { x=0, time=fxTime } )
– showFx = transition.to ( currView, { x=display.contentWidth*-1, time=fxTime } )

– instead, wait a little then perform the transition
timer.performWithDelay(300, function()
showFx = transition.to ( nextView, { x=0, time=fxTime } )
showFx = transition.to ( currView, { x=display.contentWidth*-1, time=fxTime } )
end)

– also, amend timer’s delay for cleanup
timer.performWithDelay( fxTime+300+safeDelay, fxEnded )[/lua]

If you had the same problem, please let me know if this worked for you. [import]uid: 52103 topic_id: 10772 reply_id: 310772[/import]

The above code can be improved a little by adding these changes:

  • using postLoadDelay global
  • moving second performWithDelay call inside the first one
  • using screenOriginX to make sure nextView is off screen before transition starts (otherwise it may show up right next to the currView in “letterbox” configuration)

[lua]if effect == “moveFromRight” then

nextView.x = display.contentWidth - display.screenOriginX
nextView.y = 0

loadScene (newScene)

timer.performWithDelay(postLoadDelay, function()
transition.to ( nextView, { x=0, time=fxTime } )
transition.to ( currView,
{ x=display.contentWidth*-1 + display.screenOriginX, time=fxTime } )

timer.performWithDelay( fxTime+safeDelay, fxEnded )
end)[/lua] [import]uid: 52103 topic_id: 10772 reply_id: 39167[/import]