Hi, everyone
I was using Director Class and I was running into a problem with it for my game and I couldn’t find out the problem. So, I decided to make my own level changer and everything was going good. The levels change very nicely, but when I decided to add in a fade I ran into a problem. It fades. But instead of fading, then changing the scene, then fading back. It fades, then shows a blip of the previous scene, then just instantly shows the next scene without a fade…
This is the level changer code (everything is in the same lua file and it jsut makes the view(camera) jump to different locations on the screen to make it seem like its changing levels):
All of my display objects are inserted into the [lua]sceneControl[/lua] group to allow this to work.[lua]local sceneControl = display.newGroup()
local sceneScreen = display.newRect(0,0,480,320)
sceneScreen:setReferencePoint(display.TopLeftReferencePoint)
sceneScreen.x = 0
sceneScreen.y = 0
sceneScreen.alpha = 0
sceneScreen:setFillColor(0,0,0)[/lua]
Each “new scene” is specified by a transparent screen sized rectangle at its given location.
[lua] local sceneLevel = display.newRect(0,0,480,320)
sceneLevel:setReferencePoint(display.TopLeftReferencePoint)
sceneLevel.x = 0
sceneLevel.y = 320
sceneLevel.alpha = 0[/lua]
This causes the [lua]sceneControl[/lua] group to move away from your specified location (“new scene”) giving the illusion your camera is moving.
[lua] local function menuChangeLevel()
if sceneScreen.y >= sceneLevel.y then
sceneControl.y = -sceneScreen.y + sceneLevel.y
end
if sceneScreen.x >= sceneLevel.x then
sceneControl.x = -sceneScreen.x + sceneLevel.x
end
end
Runtime:addEventListener(“enterFrame”, menuChangeLevel)[/lua]
This is supposed to create a fade in and out when the scene changes. But I do not know what the problem is.
[lua] local function pressLevelB(event)
if event.phase == “ended” then
fadeOut = true
end
end
levelB:addEventListener(“touch”, pressLevelB)
local function toLevel()
if sceneScreen.alpha == 1 then
sceneScreen.x = sceneLevel.x + sceneLevel.x
sceneScreen.y = sceneLevel.y + sceneLevel.y
fadeOut = false
end
end
Runtime:addEventListener(“enterFrame”, toLevel)
local function sceneFade()
if fadeOut == true then
sceneScreen.alpha = sceneScreen.alpha +0.1
else
sceneScreen.alpha = sceneScreen.alpha -0.1
end
end
Runtime:addEventListener(“enterFrame”, sceneFade)[/lua]
Will someone please help me figure out this problem? [import]uid: 208120 topic_id: 35646 reply_id: 335646[/import]