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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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 )

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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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)
views:521 update:2011/10/12 18:33:00
corona forums © 2003-2011