Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Tips for Those Still Using Director Class and Graphics 2.0
Started by scottadelman Sep 23 2014 02:10 PM

- - - - -
7 replies to this topic
director class graphics 2.0 corona sdk freeze touch problems screen
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

scottadelman

[GLOBAL: userInfoPane.html]
scottadelman
  • Contributor

  • 237 posts
  • Corona SDK

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:

 

1) Remove all instances of "bookBackground:addEventListener( "touch", moveBookPage )" or all code around the book in director.lua to fix touch events

 

2) Change:

local protection = display.newRect( -_W, -_H, _W * 3, _H * 3 )
protection:setFillColor( 255, 255, 255 )

 

To:

local protection = display.newRect( -_W, -_H, _W * 3, _H * 3 )
protection.anchorX = 0
protection.anchorY = 0
protection:setFillColor( 1, 1, 1 )

 

To help fix issues with activating touch events during transitions.

 

3) Add:

local function listenertothis( )
        director:changeScene( "WHATEVERTHESCENEIS","crossfade" )
end
timer.performWithDelay( 200, listenertothis )

 

To your code any time a changescene could be called shortly after the scene is loaded

 

4) Change:

local fxTime = 200
local safeDelay = 50

 

To:

local fxTime = 500
local safeDelay = 100

 

5) To fix fade:

For fade:

Change-

nextView.x = _W
nextView.y = 0
 
local fade = display.newRect( -_W, -_H, _W * 3, _H * 3 )
 

to:

nextView.x = _W*2
nextView.y = mynewyvalue
        --
local fade = display.newRect( -_W, -_H, _W * 3, _H * 3 )
fade.anchorX = 0
fade.anchorY = 0

 

 

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:

bookBackground:addEventListener( "touch", moveBookPage )

 

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:

local protection = display.newRect( -_W, -_H, _W * 3, _H * 3 )
protection:setFillColor( 255, 255, 255 )

 

To:

local protection = display.newRect( -_W, -_H, _W * 3, _H * 3 )
protection.anchorX = 0
protection.anchorY = 0
protection:setFillColor( 1, 1, 1 )

 

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:

local function listenertothis( )
        director:changeScene( "WHATEVERTHESCENEIS","crossfade" )
end
timer.performWithDelay( 200, listenertothis )

 

 

This will center the protection rectangle

 

Transitions arent like they used to be on the device?

 

Change:

local fxTime = 200
local safeDelay = 50

 

To:

local fxTime = 500
local safeDelay = 100

 

For fade:

Change-

nextView.x = _W
nextView.y = 0
 
local fade = display.newRect( -_W, -_H, _W * 3, _H * 3 )
 

to:

nextView.x = _W*2
nextView.y = mynewyvalue
        --
local fade = display.newRect( -_W, -_H, _W * 3, _H * 3 )
fade.anchorX = 0
fade.anchorY = 0

 

 

Hopefully this helps someone out there.. let me know if you find any other quirks..

 

 

 

 



[TOPIC: post.html]
#2

elbowroomapps

[GLOBAL: userInfoPane.html]
elbowroomapps
  • Contributor

  • 353 posts
  • Corona SDK

Thanks for this very useful post. Have you modified your version of director to not use module(..., package.seeall)? I think the last official version might still have that, but there are versions floating around with  that removed.

 

I'm also still using director class. I've come to the conclusion that I should always choose an open source solution when one is available. Otherwise you will find yourself stuck waiting for someone else to fix a bug or add a new feature. 



[TOPIC: post.html]
#3

scottadelman

[GLOBAL: userInfoPane.html]
scottadelman
  • Contributor

  • 237 posts
  • Corona SDK

No problem!  I have not removed module(..., package.seeall) form those apps. I know it is not best practice, but rewriting 20 some apps to comply without it doesn't seem worth my time since they already are working great with the above modifications.



[TOPIC: post.html]
#4

dingo

[GLOBAL: userInfoPane.html]
dingo
  • Contributor

  • 700 posts
  • Corona SDK

@scott: thanks a lot for this topic. I almost gave up with it :)



[TOPIC: post.html]
#5

scottadelman

[GLOBAL: userInfoPane.html]
scottadelman
  • Contributor

  • 237 posts
  • Corona SDK

Happy to help @dingo!  Not sure how many of the Director Class using sorts of us are left :)  I remember your app that is in your profile picture.  I downloaded it when it came out and was definitely amazed at what you created.  Love that character :)

 

If anyone wants a copy of the director class I am currently using, let me know.  I did some trimming of certain functions that I never used.  The only thing that bothers me with Director is that the scene transition timing is inconsistent depending on the graphics load being used.  So sometimes the transition is much longer than I would want, but then again, I didnt have to rewrite a ton of apps.. so I cant complain much.  If anyone figures out a better way for the timing, let me know.



[TOPIC: post.html]
#6

beanmachine1987

[GLOBAL: userInfoPane.html]
beanmachine1987
  • Observer

  • 6 posts
  • Corona SDK

Happy to help @dingo!  Not sure how many of the Director Class using sorts of us are left :)  I remember your app that is in your profile picture.  I downloaded it when it came out and was definitely amazed at what you created.  Love that character :)

 

If anyone wants a copy of the director class I am currently using, let me know.  I did some trimming of certain functions that I never used.  The only thing that bothers me with Director is that the scene transition timing is inconsistent depending on the graphics load being used.  So sometimes the transition is much longer than I would want, but then again, I didnt have to rewrite a ton of apps.. so I cant complain much.  If anyone figures out a better way for the timing, let me know.

 

hey, I know this post is rather dated, but I just wanted to say thank you for this very informative post! Also, if you still have your version of director laying around I'd love to try it out.

 

Joey



[TOPIC: post.html]
#7

scottadelman

[GLOBAL: userInfoPane.html]
scottadelman
  • Contributor

  • 237 posts
  • Corona SDK

Hey Joey,

 

No problem.  Send me a PM and Ill get you a link to it.

 

Scott



[TOPIC: post.html]
#8

MBD

[GLOBAL: userInfoPane.html]
MBD
  • Contributor

  • 384 posts
  • Corona SDK

Can I get a copy of that link as well? I'm facing the same issue - I have some legacy apps I really don't want to bother porting to composer just yet (for sake of time).

 

Thanks!




[topic_controls]
[/topic_controls]