Director 1.3 released!

Hey guys,

Check this out:

http://rauberlabs.blogspot.com/2011/07/director-class-13.html [import]uid: 8556 topic_id: 11895 reply_id: 311895[/import]

Right on time, thank you!

Changes are huge but all makes sense, I wasn’t expecting that kind rewrite :slight_smile:

I’ll try that with my current project and report back soon… [import]uid: 10478 topic_id: 11895 reply_id: 43381[/import]

The new version is fantastic. Great work and thanks, Ricardo! [import]uid: 6084 topic_id: 11895 reply_id: 43384[/import]

@Ricardo, got a Q if you can help me plz…

Regarding “Call to clean() function removed”

I was using cleanup function to remove unnecessary sound files, sprite sheets as well as the particles (Particle Candy) used on screen AFTER the scene is changed.

I can use my own clean function as suggested but I’ll still need that function called AFTER the scene change.

For example, I have some sprite & particle animation (Particle Candy) on screen. If I assign my clean function to the button that changes the screen, everything disappears on screen before the scene change happen.

So, do you have any suggestion for that? For now I think I’ll either use a loader screen that cleans up the previous one then calls the next screen OR I’ll put back clean up function to 1.3. [import]uid: 10478 topic_id: 11895 reply_id: 43400[/import]

If you really need you can put it back. No worries but my advice is to put it as a method, like this:

localGroup.clean = function () ... end  

I am thinking on something bigger then only a clean() function but still researching.

Thanks guys [import]uid: 8556 topic_id: 11895 reply_id: 43407[/import]

Hi Ricardo… 1.3 looks very nice indeed!

I’m also very keen on the clean function, but would like director to call the function automatically each time i change the scene. If I place “localGroup.clean = function () … end” in my scene modules
what changes would i need to do in the director module in order to call the clean function on each scene change?

Thanks [import]uid: 13632 topic_id: 11895 reply_id: 43541[/import]

Hi!

First time really using Director.

How do I get it to use @2x images for higher resolution screens?

Cheers! [import]uid: 10389 topic_id: 11895 reply_id: 43583[/import]

Amazing work! Director is what actually convinced me to make Bubble Ball in Corona (Scene management before director was horrible, and I didn’t understand it at all), so thank you! [import]uid: 8782 topic_id: 11895 reply_id: 43589[/import]

The clean function is very important to the Director Class, I feel, and I’d really like to get a version of 1.3 with this functionality reinstated.

If people didn’t know what it was, they don’t know how to manage the memory of their apps and shouldn’t be determining the direction of your Director Class.

This also means that I need to go over and change all the projects that use the Director Class before they will work as I intended them to. Seems strange to just remove an important hook that projects are relying on to be successful.

Apart from this issue, you’re doing some great work here… thanks [import]uid: 58388 topic_id: 11895 reply_id: 43596[/import]

@hudson.graham

+1 [import]uid: 13632 topic_id: 11895 reply_id: 43598[/import]

i second that hudson.graham , not only we have to change the existing projects we also have to call that function every time ourselves which can cause lot of errors … so far i tried 1.3 and with out clean function i am having funny errors…

so please restore the clean function [import]uid: 34898 topic_id: 11895 reply_id: 43605[/import]

+1 restore the clean function [import]uid: 12088 topic_id: 11895 reply_id: 43685[/import]

Ok guys, let’s make a deal with clean function. It can be as a module function or an object function, this is one of the things that made me cut it off.

On director 1.3 I’m suggesting to use every scene as an object of a module, so the clean function must be inside the object, ok? It could be something like this:

new = function ( params )  
 local localGroup = display.newGroup()  
  
 ...  
  
 localGroup.clean = function()  
 -- clean code  
 end  
  
 ...  
  
 return localGroup  
end  

What about all project made with clean function outside the new() function? Ok, now we know that we need 2 types of clean() function, one for the scene and one for the module, like this:

local localGroup = display.newGroup()  
  
clean = function()  
 -- clean code  
end  
  
new = function ( params )  
  
 ...  
  
 return localGroup  
end  

I’m thinking on calling it for both types but we have to agree on use “.” or “:” for the clean() inside the group. What do you guys thing about this? [import]uid: 8556 topic_id: 11895 reply_id: 43687[/import]

There is a third option, sending the function as a parameter, like this:

clearSprites = function ()  
 ...  
end  
  
director:changeScene( { clean=clearSprites }, "scene", "moveFromRight" )  

What about this? [import]uid: 8556 topic_id: 11895 reply_id: 43689[/import]

Thanks ricardorauber for getting onto this so quickly.

My background is from AS3/Drupal and I have been finding my feet over the last few weeks with lua/corona and feel I’ve finally found how to structure my code in OOP Classes.

So, to get the best outcome here, I’m going to show my class structure and how it is working with the Director Class 1.2. Hopefully this will get others to throw in their examples and we can get the best outcome for all.

DirectorSceneExample.lua

[blockcode]

– Project: DirectorClean
– Version: 1.0.1
– Date: 4 Jul 2011
– Description: An example of the current use of the Director Class using the clean function

– Version: 1.0
– Managed with http://CoronaProjectManager.com

– Copyright 2011 Hudson Graham. All Rights Reserved.

module(…, package.seeall)


– Import class

require “DirectorClassExample”

–local logger = require(“Logger”)


– LOCAL VARIABLES


– GROUPS

local localGroup = display.newGroup()


– DISPLAY OBJECTS

local classRef


– INIT VARS

local function initVars ()

classRef = DirectorClassExample:getInstance()


– Inserts

localGroup:insert(classRef)


– Positions


– Colors


– Listeners


– Listeners

end


– CLEAN

function clean ( event )
– Custom logger for checking that all the memory before cleaning
–logger.traceMemory(“start”, “ScreenGame”)

localGroup:remove(classRef)

classRef:destroy()
classRef = nil

localGroup:remove()
localGroup = nil

– Custom logger for checking that all the memory has been cleared after doing the clean
– logger.traceMemory(“end”, “ScreenGame”)
end


– NEW

function new()


– Initiate variables

initVars()


– MUST return a display.newGroup()

return localGroup

end

[/blockcode]

Note that the clean method contains classRef:destroy(). As you can see I am doing as little as posible within the Director Scene. I’m using it purely for changing scenes and cleaning up after the scenes have changed.

DirectorClassExample.lua

[blockcode]

– Project: DirectorClean
– Version: 1.0.1
– Date: 4 Jul 2011
– Description: An example of a Class that has been instantiated within the Director Class Scene

– Version: 1.0
– Managed with http://CoronaProjectManager.com

– Copyright 2011 Hudson Graham. All Rights Reserved.


– Import classes

require “Class”

– ============================================
– Constructor
– ============================================

DirectorClassExample = class( display.newGroup )

function DirectorClassExample:construct()
–logger.trace( self.name, “construct()”)

– pre init any data here

end


– Singleton constructor

function DirectorClassExample:getInstance()
if (DirectorClassExample.instance ~= nil) then
return DirectorClassExample.instance
else
DirectorClassExample:localGroup(DirectorClassExample())
creationInit()
return DirectorClassExample:localGroup()
end
end

– ============================================
– Private properties
– ============================================


– GameMain reference

DirectorClassExample.name = “DirectorClassExample”

– ============================================
– Public properties - get/set
– ============================================


– localGroup

local _localGroup = nil

function GameLimeScreen:localGroup( obj )
if (obj == nil) then
if (_localGroup == nil) then
–logger.throwError(self.name, “GameLimeScreen:localGroup() - Trying to get a value that hasn’t been set yet.”)
else
return _localGroup
end
else
_localGroup = obj
end
end

– ============================================
– Public API methods
– ============================================


– publicMethod

function DirectorClassExample:publicMethod()
– Do something here from outside this class.
– This insures encapsulation.

end


– destroy

function DirectorClassExample:destroy()
– Override this function to hook into the destroy

– This is called from the Director Scene and allows us to clear all the memory
– One the Director Class has finished the transition out

–Particles.CleanUp()
–TextCandy.CleanUp()
–physics.stop()

instance = nil

end

– ============================================
– Lifecycle methods
– ============================================


– creationInit

function creationInit()
– Override this function to hook into the creationInit
– logger.trace(DirectorClassExample.name, “creationInit()”)

– setupMethod()

– add as many setup methods as you want

– Now everything has been setup and initialised call creationComplete()
– If we needed to do any asyncronus stuff here we would call creationComplete() from
– an event listener and not just call it straight away
creationComplete()

end


– creationComplete

function creationComplete( mode )
– Override this function to hook into the creationComplete

– All setups have run and we are ready to kick this class into life

end


– resizeDisplay

function resizeDisplay()
– Override this function to hook into the resizeDisplay
end

– ============================================
– Private methods
– ============================================


– setupMethod

function setupMethod()
– Setup code

end

– ============================================
– Event handlers
– ============================================


– onCollision

function onCollision( event )
– Collion code

end


– onUpdate

function onUpdate( event )
– update code

end

[/blockcode]

This Class is where I do all the heavy lifting (with the help from Factory and Decorator classes) and I am relying on the hook clean() from the Director Class to call my DirectorClassExample:destroy().

I want to make it clear that I am happy to update my projects with the new implementation of the Director file (as I do little within the Director framework), but as you can see the clean() function is where it’s at for me. As for which is the best way to implement the clean() hook… I’m happy to be pointed in the best direction.

Note: Class.lua

[blockcode]

– Project:
– Description: Enables the implimentation of a class structure.

– Version: 1.0
– Managed with http://CoronaProjectManager.com

http://lua-users.org/wiki/SimpleLuaClasses
– This is a variant of the Implementation of class()
– and I have been unable to find the link where I got this again.

function class( base )

local bt = nil
if( base ) then
if( ‘function’ == type( base )) then
bt = base()
elseif( base._class ) then
bt = base
end
end

if( bt ) then – is a corona class
local C = {} --new class
for k,v in pairs( bt ) do
if( k ~= ‘_proxy’ ) then
C[k] = v
end
end
C._super = bt
C.__index = C

local mt = {}
mt.__call = function( tbl, … ) – instance constructor
local i = base()

for k,v in pairs( C ) do – cannot use setmetatable on instance with corona _proxy userdata
i[k] = v
end

if( i.construct ) then
i:construct( unpack( arg ))
end
return i
end
setmetatable( C, mt )
return C
else
local C = {} --new class
if( base and type( base ) == ‘table’ ) then --shallow copy of base
for k,v in pairs( base ) do
C[k] = v
end
C._super = base
end
C.__index = C

local mt = {}
mt.__call = function( tbl, … ) – instance constructor
local i = {}
setmetatable( i, C )

if base then
local super = base
while super do
if( super.construct ) then
super.construct( i, unpack( arg ))
end
super = super._super
end
end
if( i.construct ) then
i:construct( unpack( arg ))
end
return i
end
setmetatable( C, mt )
return C
end
end
[/blockcode] [import]uid: 58388 topic_id: 11895 reply_id: 43718[/import]

Ricardo,

My vote goes for module function working as before, which will also provide full backwards compatibility.

But of course integrating both (module & group at the same time) wouldn’t hurt. Your suggested “.” type will be just fine for the object function…

3rd option isn’t my choice as it won’t be backwards compatible unless we edit all director calls. [import]uid: 10478 topic_id: 11895 reply_id: 43751[/import]

Congratulations for the new version and also the support!

I have the same thoughts as PixelEnvision.
The best is the integration (module and group). [import]uid: 38658 topic_id: 11895 reply_id: 43756[/import]

Group is most important to me.
Thank you for looking into this. [import]uid: 13632 topic_id: 11895 reply_id: 43757[/import]

By the end of the month I think I will release version 1.4 with clean function, better debug and some other things. [import]uid: 8556 topic_id: 11895 reply_id: 44114[/import]

I love Director 1.3
Using it in my new non-game app. Works well :slight_smile: [import]uid: 10389 topic_id: 11895 reply_id: 44120[/import]