I am new to corona and this is my first game.
In my “main_menu.lua” file, I want the “play_button” to transition to my “level_menu.lua”. Or the “level_menu.lua” to transition to “level_1.lua”. As for the transition, I would like to use “moveFromRight” from the director class.
Now, this is my “main_menu.lua” file:
module(..., package.seeall)
local imagelookup = require("\_imagelookup")
local animlookup = require("\_animlookup")
function newmain\_menu ()
local this = display.newGroup()
local backmenu\_4 = display.newImage(imagelookup.table["Backmenu"])
backmenu\_4.x = 320
backmenu\_4.y = 480
backmenu\_4.xScale = 1
backmenu\_4.yScale = 1
backmenu\_4.isVisible = true
--
local ui = require("ui")
local play\_button = ui.newButton{
default = imagelookup.table["Buttonplay"],
over = imagelookup.table["Buttonplayover"]
}
play\_button.x = 342.8999999999999
play\_button.y = 303.825
play\_button.isVisible = true
this:insert(play\_button)
this.play\_button = play\_button
--
local level\_menu = require("level\_menu")
local handleStartTouch = function ( event )
if (event.phase == "ended") then
local level\_menu = level\_menu:newlevel\_menu()
level\_menu:setReferencePoint(display.CenterReferencePoint)
level\_menu.x = 320
level\_menu.y = 480
level\_menu.rotation = 0
end
end
this.play\_button:addEventListener("touch", handleStartTouch)
return this
end
Now, when you press “play_button” I want it to transition using “moveFromRight” to “level_menu”
I have added “director.lua”. Also, this is the code I added to my “main.lua”
-- Import director class
local director = require("director")
-- Create a main group
local mainGroup = display.newGroup()
Also, on all the pages that I want a transition (director class), do I just add:
function new()
local localGroup = display.newGroup()
and for my image/objects:
localGroup:insert(my\_image/object)
to each one?
Also, how to I specify what transition I what for a button? (play_button)
I think the best to do now is watch the video tutorial that I talk about a lot of your doubts. If you still have issues, then post it to see what is wrong.
I have seen your video. I know my post was confusing. What I was trying to understand is why I get a runtime error with director.lua in my main folder useing this code:
-- main\_menu.lua 2011-02-06T19:38:59.069-05:00
-- Stub class for \_main\_menu.lua. All modifications will be preserved.
module(..., package.seeall)
-- Main function - MUST return a display.newGroup()
function new()
local localGroup = display.newGroup()
function newmain\_menu ()
local super = require("\_main\_menu")
local this = super:newmain\_menu()
local level\_menu = require("level\_menu")
local handleStartTouch = function ( event )
if (event.phase == "ended") then
local level\_menu = level\_menu:newlevel\_menu()
level\_menu:setReferencePoint(display.CenterReferencePoint)
level\_menu.x = 320
level\_menu.y = 480
level\_menu.rotation = 0
end
end
this.play\_button:addEventListener("touch", handleStartTouch)
--
local credits\_menu = require("credits\_menu")
local handleStartTouch = function ( event )
if (event.phase == "ended") then
local credits\_menu = credits\_menu:newcredits\_menu()
credits\_menu:setReferencePoint(display.CenterReferencePoint)
credits\_menu.x = 320
credits\_menu.y = 480
credits\_menu.rotation = 0
end
end
this.credits\_button:addEventListener("touch", handleStartTouch)
--
local instructions\_menu = require("instructions\_menu")
local handleStartTouch = function ( event )
if (event.phase == "ended") then
local instructions\_menu = instructions\_menu:newinstructions\_menu()
instructions\_menu:setReferencePoint(display.CenterReferencePoint)
instructions\_menu.x = 320
instructions\_menu.y = 480
instructions\_menu.rotation = 0
end
end
this.instructions\_button:addEventListener("touch", handleStartTouch)
return this
-- MUST return a display.newGroup()
return localGroup
end
I know I have not put any of the objects in the group, but I should not be getting a runtime error.
Exactly what Director Class code should be in my main.lua?
Thank you, sorry I really am new to all this! [import]uid: 15281 topic_id: 6219 reply_id: 21486[/import]
I know that normally people think that the error is with Director but 99% is on their own code. Let’s take a look at your code, there are a lot of things to do to work properly (even without Director).
1 - Put al your require() functions at the first lines of the code, just after the module specification, like this:
module(..., package.seeall)
-- Are the file names correct?
local super = require("\_main\_menu")
local level\_menu = require("level\_menu")
local credits\_menu = require("credits\_menu")
local instructions\_menu = require("instructions\_menu")
2 - Your new() function is open, an END is missing
function new()
local localGroup = display.newGroup()
function newmain\_menu ()
...
return this
-- MUST return a display.newGroup()
return localGroup
end
3 - This newmain_menu() function is really inside the new() function? It’s confusing.
That’s it for now, take a look at the points I said and if you think that the problem is with Director, try to use yout file alone as a main.lua file in other project.
After the changes, let’s talk again. [import]uid: 8556 topic_id: 6219 reply_id: 21492[/import]
Ok, I fixed issue 1. About issue 2, were should the “end” go? after “return localGroup” at the bottom? (if so I have it) I don’t under stand issue 3. is it a question?
Here is the new code:
module(..., package.seeall)
local super = require("\_main\_menu")
local level\_menu = require("level\_menu")
local credits\_menu = require("credits\_menu")
local instructions\_menu = require("instructions\_menu")
function new()
local localGroup = display.newGroup()
function newmain\_menu ()
local this = super:newmain\_menu()
local handleStartTouch = function ( event )
if (event.phase == "ended") then
local level\_menu = level\_menu:newlevel\_menu()
level\_menu:setReferencePoint(display.CenterReferencePoint)
level\_menu.x = 320
level\_menu.y = 480
level\_menu.rotation = 0
end
end
this.play\_button:addEventListener("touch", handleStartTouch)
--
local handleStartTouch = function ( event )
if (event.phase == "ended") then
local credits\_menu = credits\_menu:newcredits\_menu()
credits\_menu:setReferencePoint(display.CenterReferencePoint)
credits\_menu.x = 320
credits\_menu.y = 480
credits\_menu.rotation = 0
end
end
this.credits\_button:addEventListener("touch", handleStartTouch)
--
local handleStartTouch = function ( event )
if (event.phase == "ended") then
local instructions\_menu = instructions\_menu:newinstructions\_menu()
instructions\_menu:setReferencePoint(display.CenterReferencePoint)
instructions\_menu.x = 320
instructions\_menu.y = 480
instructions\_menu.rotation = 0
end
end
this.instructions\_button:addEventListener("touch", handleStartTouch)
return this
-- MUST return a display.newGroup()
return localGroup
end
Once again thank you for your time. [import]uid: 15281 topic_id: 6219 reply_id: 21540[/import]
module(..., package.seeall)
local super = require("\_main\_menu")
local level\_menu = require("level\_menu")
local credits\_menu = require("credits\_menu")
local instructions\_menu = require("instructions\_menu")
function newmain\_menu ()
local this = super:newmain\_menu()
function new()
local localGroup = display.newGroup()
--
return localGroup -- MUST return a display.newGroup()
end
return this
end
Is it ok to but the local group inside “newmain_menu”?
Also, what code should I now add to my main.lua?
Is this good?:
-- Import director class
local director = require("director")
-- Create a main group
local mainGroup = display.newGroup()
-- Main function
local function main()
No no, your are doing it wrong. The new() function must not be inside anything. Please take a look at the demo that came with Director, there are a file called tutorial.lua where you can see how to make your own file. Besides, there are a main.lua file too, you just need to take a quick look at it and try to understand that. It’s very easy and simple. [import]uid: 8556 topic_id: 6219 reply_id: 21931[/import]