Trying to learn Director and creating a sample template and I am having some difficulty getting back to the main menu after transitioning to another scene.
I have 4 basic lua file
main
menu
creditsScene
playScene
Everything goes ok to start, menu come up just fine, press either button and it switches to different background but when I move to either the playScene or creditsScene my event listener doesn’t go back to the menu (like I think it should).
Any help to a new developer would be helpful. I am obviously missing something easy - just can’t understand what I am missing.
____________________
main.lua
____________________
_W = display.contentWidth;
_H = display.contentHeight;
local director = require(“director”);
local mainGroup = display.newGroup();
local function main()
mainGroup:insert(director.directorView);
director:changeScene(“menu”);
return true;
end
main();
____________________
menu.lua
____________________
module(…, package.seeall)
function new()
local localGroup = display.newGroup();
local bg = display.newImageRect(“bg.png”,_W, _H);
bg:setReferencePoint(display.CenterReferencePoint);
bg.x = _W/2; bg.y = _H/2;
local title = display.newImageRect(“title.png”, _W, 250);
title:setReferencePoint(display.CenterReferencePoint);
title.x = _W/2; title.y = title.height;
local play_btn = display.newImageRect(“play-btn.png”, _W, 125);
play_btn:setReferencePoint(display.CenterReferencePoint);
play_btn.x = _W/2; play_btn.y = _H/2 + play_btn.height;
play_btn.scene = “playScene”
local credits_btn = display.newImageRect(“credits-btn.png”, _W, 125);
credits_btn:setReferencePoint(display.CenterReferencePoint);
credits_btn.x = _W/2; credits_btn.y = _H/2 + play_btn.height + 100;
credits_btn.scene = “creditsScene”
function changeScene(e)
if(e.phase == “ended”) then
director:changeScene(e.target.scene);
end
end
_______________________
creditsScene.lua
_______________________
module (…, package.seeall);
function new ()
local localGroup = display.newGroup();
local credits = display.newImageRect(“bg_credits.png”, _W, _H);
credits:setReferencePoint(display.CenterReferencePoint);
credits.x = _W/2; credits.y = _H/2;
credits.scene = “menu”;
localGroup:insert(credits);
function changeScene(e)
if(e.phase == “ended”) then
direct:changeScene(e.target.scene);
end
end
credits:addEventListener(“touch”, changeScene)
return localGroup;
end
_______________________
playScene.lua
_______________________
module (…, package.seeall);
function new ()
local localGroup = display.newGroup();
local playgame = display.newImageRect(“bg_game.png”, _W, _H);
playgame:setReferencePoint(display.CenterReferencePoint);
playgame.x = _W/2; playgame.y = _H/2;
playgame.scene = “menu”;
localGroup:insert(playgame);
function changeScene(e)
if(e.phase == “ended”) then
direct:changeScene(e.target.scene);
end
end
playgame:addEventListener(“touch”, changeScene)
return localGroup;
end
[import]uid: 115952 topic_id: 21091 reply_id: 321091[/import]

