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