This is the codes , that I wrote :
main.lua:
[code]_H = display.contentHeight;
_W = display.contentWidth;
local director = require(“director”);
local mainGroup = display.newGroup();
local function main()
mainGroup:insert(director.directorView);
director:changeScene(“menu”);
return true;
end
main();[/code]
menu.lua
[code]module(…,package.seeall);
function new()
local localGroup = display.newGroup();
local BG = display.newImageRect(“images/BGR.PNG” , _W , _H);
BG:setReferencePoint(display.CenterReferencePoint);
BG.x = _W/2; BG.y = _H/2;
local title = display.newImageRect(“images/title.PNG” , _W , 115);
title:setReferencePoint(display.CenterReferencePoint);
title.x = _W/2; title.y = title.height;
title.rotation = -30;
local playBtn = display.newImageRect(“images/play-btn.PNG” , _W-200 , 75);
playBtn:setReferencePoint(display.CenterReferencePoint);
playBtn.x = _W/2; playBtn.y = _H/2 + playBtn.height;
playBtn.scene = “game”;
local creditsBtn = display.newImageRect(“images/credits-btn.PNG” , _W-200 , 75);
creditsBtn:setReferencePoint(display.CenterReferencePoint);
creditsBtn.x = _W/2; creditsBtn.y = _H/2 + playBtn.height + creditsBtn.height;
creditsBtn.scene = “credits”;
function changeScene(e)
if(e.phase == “ended”)then
director:changeScene(e.target.scene);
end
end
localGroup:insert(BG);
localGroup:insert(title);
localGroup:insert(playBtn);
localGroup:insert(creditsBtn);
playBtn:addEventListener(“touch” , changeScene);
creditsBtn:addEventListener(“touch” , changeScene);
return localGroup;
end[/code]
credits.lua
[code]module(…, package.seeall);
function new()
local localGroup = display.newGroup();
local omar = display.newText(“OMAR” , 0 , 0 , native.systemFont , 32*2);
omar:setReferencePoint(display.CenterReferencePoint);
omar.x = _W/2; omar.y = _H/2;
omar.scene = “menu”;
localGroup:insert(omar);
function changeScene(e)
if(e.phase == “ended”)then
director:changeScene(e.target.scene);
end
end
omar:addEventListener(“touch” , changeScene);
return localGroup;
end[/code]
Actually,now when I hit the game button it works good… but when I hit the credits button it gives me an error and it says:
“Director ERROR: Module ‘credits’ must have a new() function.”
though I have a function called new() in the credits.lua !!
[import]uid: 133838 topic_id: 24374 reply_id: 98689[/import]