Graphics 2.0 - opening rect flash & broken video (mov) transition

Due to early Storyboard instability, I have stuck with director.lua for scene changes. Implementing G2.0 has introduced the following problems:

  1. fade in/out of a black rectangle in upper-left-screen quadrant on opening any lua file (module)

2) a broken video (mov) changeScene transition

Re: broken video

 

On changeScene to open/close intro.lua, specified fade effect is ignored and replaced by slide effect – sliding the wrong screen.

 

A] On open intro.lua, current screen slidesDown, reveals black bg w/mov controls, intro.lua bg appears

 

B] On close intro.lua, the pre-intro-legacy screen (from A open ) slides up, disappears, reveals menu.lua bg

 

I’ll include intro.lua and sample changeScene code below.

 

I have tried every iteration that I can think of. Any thoughts/suggestions for what I can try to fix either of these problems? Thank you very much for any  help that you can give.

 

 

—————[  intro.lua code  ]————————

[lua]

–intro.lua - plays intro.mov returns to main screen (menu.lua) when movie ends or user selects movie player controls’ “Done” button

module(…, package.seeall);

function new()

local localGroup = display.newGroup();

local bg = display.newImage( “images/bgmov.png” )

local movie = “media/intro.mov”; 

       


– CHANGE SCENE


local changeScene = function ( e )

localGroup:remove(movie)

director:changeScene( “menu” , “fade” )

end

tmr = timer.performWithDelay(1500, changeScene , 1)


– PLAY VIDEO


– Determine if running on Corona Simulator

local isSimulator = “simulator” == system.getInfo(“environment”)

– Video is not supported on Simulator

if isSimulator then

display.newText( “No Video on Simulator!”, 0, 60, “Verdana-Bold”, 22 )

else

media.playVideo( “media/intro.mov”, true, changeScene );

end

localGroup:insert(bg);

return localGroup;

end

[/lua]

—————[  puzzle.lua’s changeScene code - works with every other lua module]————————

[lua]

–***************************************************

–*********  CHANGESCENE  ***************************

–***************************************************

function changeScene(e)

if(e.phase == “ended”) then

for i = localGroup.numChildren, 1, -1 do–traversing puzz backward

localGroup[i]:removeSelf();

localGroup[i] = nil;

end 

director:changeScene(e.target.scene, “fade”);

end

end

[/lua]

@Ibolduc: Regarding the black rectangle, by guess is that it’s a screen-sized display.newRect being constructed at 0,0, which used to be top-left aligned, and is now center-aligned. I saw this same issue in my game when switching to Graphics 2.0, as I wrote my own fade in function. I would look through the director code for fade-in and see if that’s the case, and add .anchorX and .anchorY = 0 lines.

@davidcondolora, thanks very much. i combed over the fade code and couldn’t find anything. i’ve spent the day pouring over Composer documentation and the updated Brian Burton book’s Composer info. there are similarities b/t Storyboard/Composer-execution logic and the Director changeScene-error scenario. Ricardo Rauber told me that he’s no longer using Corona … not a good sign for Director’s future … but, who didn’t see that coming, right? I’ll spend some time wrestling with Composer and see how it goes. I appreciate your help and suggestions.

@Ibolduc: You’re welcome! I just migrated to Composer from Storyboard, and it took at most a couple of hours. Much better than the (still-ongoing) Graphics 2.0 migration. But Director is a bit different, so it will likely take a bit longer. Still, I think it’s probably worth it. Good luck!

NOTE: Black rect problem solved. A bug report has been filed on the video problem.

@davidcondolora … aka _genius_! you were right. inserting anchorX/Ys into Ricardo Rauber’s fade-effect code in director.lua 1.3 file eliminated the black rect flash. transitions beautifully everywhere except video … extremely frustrating.

thank you so much for your help!

for anyone using director 1.3, this is the fade-effect-code edit that’s working for me:

[lua]

elseif effect == “fade” then

        

local r, g, b = getColor ( arg1, arg2, arg3 )

nextView.x = display.contentWidth

nextView.y = 0

nextView.anchorX = 0;

nextView.anchorY = 0;

loadScene (newScene)

local fade = display.newRect( 0 - display.contentWidth, 0 - display.contentHeight, display.contentWidth * 3, display.contentHeight * 3 )

fade.anchorX = 0; fade.anchorY = 0;

fade.alpha = 0

fade:setFillColor( r,g,b )

effectView:insert(fade)

showFx = transition.to ( fade, { alpha=1.0, time=fxTime } )

timer.performWithDelay( fxTime+safeDelay, fxEnded )

local function returnFade ( event )

                

showFx = transition.to ( fade, { alpha=0, time=fxTime } )

local function removeFade ( event )

fade:removeSelf()

end

timer.performWithDelay( fxTime+safeDelay, removeFade )

end

timer.performWithDelay( fxTime+safeDelay+1, returnFade )

[/lua]

@Ibolduc: Glad to be of service! :slight_smile: Thanks for posting the fix for everyone!

  • David

@Ibolduc and @davidcondolora

I am having two issues.

  1. The crossfade function in Director Class is not working properly when on the device. It just jumps from once scene to the next; however, on the simulator, it transitions appropriately. Have no clue what is going on here.

  2. A big deal for all. If a button is pressed that changes a scene just after the transition is complete, the app will freeze. This appears to occur on the device only; however, I was pretty certain I caused it in the simulator as well. No error messages are provided when it occurs. I cannot figure out why this is. In graphics 1.0 this was 100% not an issue. I thought it may have to do with the protection rect that is placed over the scene during transition not covering correctly. I fixed this, and it happens immediately after the protection is removed.

Thanks!

@scottadelman,

I’ve had effects freeze and otherwise freak out when the changeScene timing is off. Graphics 2.0. seems to move faster. Maybe too fast for older settings?

I played with director 1.3’s time control variables. Found this works well for fades in my app. Crossfade and/or your app’s needs may vary.

local fxTime = 500;

local safeDelay = 100;

Hope this helps. Good luck!

@scottadelman: Maybe this will help with your second problem. I haven’t used Director, but I had similar issues with my fadeOut function in Graphics 2.0. The function draws a black rectangle on screen, transitions its alpha to 100%, then changes the scene. In Graphics 2.0 builds, the scene change would happen before the black rectangle was 100%, which means that the “onComplete” part of the transition was firing before the transition was actually complete. The solution was to trigger the scene change via a 100ms timer that would be started after the rectangle finished transitioning.

@davidconolora and @Ibolduc thank you both for your input.

I tried what you recommended @davidcondolora. It seemed likely, but is still occurring… the only solution I have found is outside of director by putting a delay like so:

[lua]local function listenertothis( )
director:changeScene( “title”,“fade” )
end
timer.performWithDelay( 50, listenertothis )[/lua]

This seems to ensure that scenes are done transitioning and the call wont cause a crash.  I was hoping to have a way to place this in director; however, adding the delay in director does not resolve this issue.

@Ibolduc thank you for the tip.  It does appear now during transitions although it is quite a difference watching the Graphics 1.0 and 2.0 load.  1.0 is significantly faster, which I thought it was supposed to be the other way around… oh well.  I was hoping the “local safeDelay = 100” would solve it, but apparently that is only a delay that is used when no effect is in place and it did not solve the issue.

If anyone has any other ideas what might be going on, please let me know.  Changing the director.lua seems a lot better than combing through all my code to modify.

Scott

@scottadelman: For what it’s worth, I migrated my game from Storyboard to Composer over about 4 or 5 hours, and found the process relatively painless. However, I haven’t used Director, so I can’t speak to the difficulty there. Given the problems you’re running into though, it may be worth it to bite the bullet, especially because Director is only going to become more out of date.

Regarding speed in Graphics 2.0, I heartily agree; I expected it to be faster, but found it to be slower, and timing of transitions and timers to be off. Even when things worked properly, my game just felt “different” running under Graphics 2.0, with animations moving at subtly different speeds, and odd problems similar to the one you described. Not a huge fan, but not much we can do about it. Though I did manage to get the latest update to my game through to the App Store under Graphics 1.0.

@Ibolduc: Regarding the black rectangle, by guess is that it’s a screen-sized display.newRect being constructed at 0,0, which used to be top-left aligned, and is now center-aligned. I saw this same issue in my game when switching to Graphics 2.0, as I wrote my own fade in function. I would look through the director code for fade-in and see if that’s the case, and add .anchorX and .anchorY = 0 lines.

@davidcondolora, thanks very much. i combed over the fade code and couldn’t find anything. i’ve spent the day pouring over Composer documentation and the updated Brian Burton book’s Composer info. there are similarities b/t Storyboard/Composer-execution logic and the Director changeScene-error scenario. Ricardo Rauber told me that he’s no longer using Corona … not a good sign for Director’s future … but, who didn’t see that coming, right? I’ll spend some time wrestling with Composer and see how it goes. I appreciate your help and suggestions.

@Ibolduc: You’re welcome! I just migrated to Composer from Storyboard, and it took at most a couple of hours. Much better than the (still-ongoing) Graphics 2.0 migration. But Director is a bit different, so it will likely take a bit longer. Still, I think it’s probably worth it. Good luck!

NOTE: Black rect problem solved. A bug report has been filed on the video problem.

@davidcondolora … aka _genius_! you were right. inserting anchorX/Ys into Ricardo Rauber’s fade-effect code in director.lua 1.3 file eliminated the black rect flash. transitions beautifully everywhere except video … extremely frustrating.

thank you so much for your help!

for anyone using director 1.3, this is the fade-effect-code edit that’s working for me:

[lua]

elseif effect == “fade” then

        

local r, g, b = getColor ( arg1, arg2, arg3 )

nextView.x = display.contentWidth

nextView.y = 0

nextView.anchorX = 0;

nextView.anchorY = 0;

loadScene (newScene)

local fade = display.newRect( 0 - display.contentWidth, 0 - display.contentHeight, display.contentWidth * 3, display.contentHeight * 3 )

fade.anchorX = 0; fade.anchorY = 0;

fade.alpha = 0

fade:setFillColor( r,g,b )

effectView:insert(fade)

showFx = transition.to ( fade, { alpha=1.0, time=fxTime } )

timer.performWithDelay( fxTime+safeDelay, fxEnded )

local function returnFade ( event )

                

showFx = transition.to ( fade, { alpha=0, time=fxTime } )

local function removeFade ( event )

fade:removeSelf()

end

timer.performWithDelay( fxTime+safeDelay, removeFade )

end

timer.performWithDelay( fxTime+safeDelay+1, returnFade )

[/lua]

@Ibolduc: Glad to be of service! :slight_smile: Thanks for posting the fix for everyone!

  • David

@Ibolduc and @davidcondolora

I am having two issues.

  1. The crossfade function in Director Class is not working properly when on the device. It just jumps from once scene to the next; however, on the simulator, it transitions appropriately. Have no clue what is going on here.

  2. A big deal for all. If a button is pressed that changes a scene just after the transition is complete, the app will freeze. This appears to occur on the device only; however, I was pretty certain I caused it in the simulator as well. No error messages are provided when it occurs. I cannot figure out why this is. In graphics 1.0 this was 100% not an issue. I thought it may have to do with the protection rect that is placed over the scene during transition not covering correctly. I fixed this, and it happens immediately after the protection is removed.

Thanks!

@scottadelman,

I’ve had effects freeze and otherwise freak out when the changeScene timing is off. Graphics 2.0. seems to move faster. Maybe too fast for older settings?

I played with director 1.3’s time control variables. Found this works well for fades in my app. Crossfade and/or your app’s needs may vary.

local fxTime = 500;

local safeDelay = 100;

Hope this helps. Good luck!

@scottadelman: Maybe this will help with your second problem. I haven’t used Director, but I had similar issues with my fadeOut function in Graphics 2.0. The function draws a black rectangle on screen, transitions its alpha to 100%, then changes the scene. In Graphics 2.0 builds, the scene change would happen before the black rectangle was 100%, which means that the “onComplete” part of the transition was firing before the transition was actually complete. The solution was to trigger the scene change via a 100ms timer that would be started after the rectangle finished transitioning.

@davidconolora and @Ibolduc thank you both for your input.

I tried what you recommended @davidcondolora. It seemed likely, but is still occurring… the only solution I have found is outside of director by putting a delay like so:

[lua]local function listenertothis( )
director:changeScene( “title”,“fade” )
end
timer.performWithDelay( 50, listenertothis )[/lua]

This seems to ensure that scenes are done transitioning and the call wont cause a crash.  I was hoping to have a way to place this in director; however, adding the delay in director does not resolve this issue.

@Ibolduc thank you for the tip.  It does appear now during transitions although it is quite a difference watching the Graphics 1.0 and 2.0 load.  1.0 is significantly faster, which I thought it was supposed to be the other way around… oh well.  I was hoping the “local safeDelay = 100” would solve it, but apparently that is only a delay that is used when no effect is in place and it did not solve the issue.

If anyone has any other ideas what might be going on, please let me know.  Changing the director.lua seems a lot better than combing through all my code to modify.

Scott