Trying To Add Fade Effects To Director Slim Class By Lerg

Hej,

so I tried to add fade effects to the mighty Director Slim Class by Lerg ,but I think I am stuck at passing the new scene data 

    local nextView = display.newGroup()

    nextView:insert ( require( moduleName ).new() )

to

self.view = nextView

… I tried using a table and a display Group, but can’t quite figure out, what I am doing wrong.

This is my attempt so far:

local director = {scene = ‘main’}

function director:changeScene ( moduleName, transitionType )

    if type(moduleName) == ‘nil’ or self.scene == moduleName then 

        

        return 

    

    end

    

    local loadedModule = package.loaded[self.scene]

    local nextView = display.newGroup()

    nextView:insert ( require( moduleName ).new() )

------------------------------------------------------------------------- CLEAN & LOAD --------------------------------------------------------------------------

    

    local function changeThis()

        if type(loadedModule) == ‘table’ and type(loadedModule.clean) == ‘function’ then

            loadedModule.clean()

        end

        if self.view then 

            self.view:removeSelf() 

        end

        if self.scene ~= ‘main’ and type(loadedModule) == ‘table’ then

            package.loaded[self.scene], self.view, loadedModule, nextView = nil

            collectgarbage(‘collect’)

        end

        self.view = nextView

        self.scene = moduleName

        if nextView then

        

            nextView = nil

            

        end

    end

------------------------------------------------------------------------- TRANSITIONS --------------------------------------------------------------------------

    

    if transitionType == “fade” then

    

        print (self.scene… " fade " …moduleName)

        nextView.x = 1000

        nextView.y = 0

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

        fade.alpha = 0

        fade:setFillColor( 0 )

        local function returnFade( event )

        

            self.view.x = 1000

            nextView.x = 0

            local function removeFade( event )

            

                fade:removeSelf()

                changeThis()

        

            end

            transition.to( fade, { alpha = 0, time = 1000, onComplete = removeFade } )

        end

        transition.to( fade, { alpha = 1.0, time = 1000, onComplete = returnFade } )

    

    elseif transitionType == “swipeToRight” then

    

        print (self.scene… " swipeToRight " …moduleName)

        nextView.x = display.contentWidth

        nextView.y = 0

        

        transition.to( nextView, { x = 0, time = 300 } )

        transition.to( self.view, { x = -display.contentWidth, time = 1000, onComplete = changeThis } )

        

    else

    

        changeThis()

    

    end

end

return director

I would love it, if someone could help me out.

Thanks a lot guys!

Philip

Hi Philip,

In one app, I use a sort of customized “Director Slim” based on Lerg’s original template. What I found to be the best solution is to just handle transitions at the scene level instead of trying to build in some kind of fade/transition functionality into Director Slim itself.

For example, if I want a scene to fade in, I just set the scene’s umbrella display group to alpha=0 when I declare the group hierarchy at the beginning. Then I load my content and do a simple transition to alpha=1. Same basic idea on fade out, slide from left, whatever.

Hope this helps,

Brent

Hi Philip,

In one app, I use a sort of customized “Director Slim” based on Lerg’s original template. What I found to be the best solution is to just handle transitions at the scene level instead of trying to build in some kind of fade/transition functionality into Director Slim itself.

For example, if I want a scene to fade in, I just set the scene’s umbrella display group to alpha=0 when I declare the group hierarchy at the beginning. Then I load my content and do a simple transition to alpha=1. Same basic idea on fade out, slide from left, whatever.

Hope this helps,

Brent

Hej Brent, thanks for your reply.

I now do a manual in and out animation per Scene.

Hej Brent, thanks for your reply.

I now do a manual in and out animation per Scene.