I haven’t seen much on Director Class in a while and good for you out there who moved away from it a loooonnnggg time ago, but for those of you who haven’t I wanted to provide some info I figured out over time and from various forum posts about Director Class and Graphics 2.0.
I’ll list first what should be altered and then explanations and more info below:
-
Remove all instances of “bookBackground:addEventListener( “touch”, moveBookPage )” or all code around the book in director.lua to fix touch events
-
Change:
[lua]local protection = display.newRect( -_W, -_H, _W * 3, _H * 3 )
protection:setFillColor( 255, 255, 255 )[/lua]
To:
[lua]local protection = display.newRect( -_W, -_H, _W * 3, _H * 3 )
protection.anchorX = 0
protection.anchorY = 0
protection:setFillColor( 1, 1, 1 )[/lua]
To help fix issues with activating touch events during transitions.
- Add:
[lua]local function listenertothis( )
director:changeScene( “WHATEVERTHESCENEIS”,“crossfade” )
end
timer.performWithDelay( 200, listenertothis )[/lua]
To your code any time a changescene could be called shortly after the scene is loaded
- Change:
[lua]local fxTime = 200
local safeDelay = 50[/lua]
To:
[lua]local fxTime = 500
local safeDelay = 100[/lua]
- To fix fade:
For fade:
Change-
[lua]
nextView.x = _W
nextView.y = 0
local fade = display.newRect( -_W, -_H, _W * 3, _H * 3 )
[/lua]
to:
[lua]nextView.x = _W*2
nextView.y = mynewyvalue
–
local fade = display.newRect( -_W, -_H, _W * 3, _H * 3 )
fade.anchorX = 0
fade.anchorY = 0[/lua]
There is a forum post that addresses an error with touch events:
http://forums.coronalabs.com/topic/43375-touch-events-in-graphic-20/
It indicates that you can just get rid of this line in 3 places:
[lua]bookBackground:addEventListener( “touch”, moveBookPage )[/lua]
In fact you can completely remove all references to the book if you want if you aren’t using it… if you are, then you just need to adjust the bookBackground rect to cover the whole screen on any device.
This does resolve the touch event issue but it is not sufficient for a better working Director Class
There is a protection rectangle that covers the screen during transitions to keep users from pushing touch and tap listeners. Pressing one during the transition can cause the app to crash (and will definitely crash if is a listener that changes scene)
To fix change:
[lua]local protection = display.newRect( -_W, -_H, _W * 3, _H * 3 )
protection:setFillColor( 255, 255, 255 )[/lua]
To:
[lua]local protection = display.newRect( -_W, -_H, _W * 3, _H * 3 )
protection.anchorX = 0
protection.anchorY = 0
protection:setFillColor( 1, 1, 1 )[/lua]
While fixing the protection rectangle helps prevent errors, I was still finding that if a listener with a changescene was pressed just as the scene was loaded, it was causing a crash. To fixed this I needed to add a timer.performWithDelay to any listeners in my apps code that changed scenes:
[lua]local function listenertothis( )
director:changeScene( “WHATEVERTHESCENEIS”,“crossfade” )
end
timer.performWithDelay( 200, listenertothis )[/lua]
This will center the protection rectangle
Transitions arent like they used to be on the device?
Change:
[lua]local fxTime = 200
local safeDelay = 50[/lua]
To:
[lua]local fxTime = 500
local safeDelay = 100[/lua]
For fade:
Change-
[lua]
nextView.x = _W
nextView.y = 0
local fade = display.newRect( -_W, -_H, _W * 3, _H * 3 )
[/lua]
to:
[lua]nextView.x = _W*2
nextView.y = mynewyvalue
–
local fade = display.newRect( -_W, -_H, _W * 3, _H * 3 )
fade.anchorX = 0
fade.anchorY = 0[/lua]
Hopefully this helps someone out there… let me know if you find any other quirks…
