I'm trying to create a splash screen for my game with a a few buttons on it. I'm trying to figure out how to make my Play button take the user to the first level (aka next screen)
I'm trying to use Ricardo and Peach's example. Heres what I'm looking at:
Menu.lua
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | local background = display.newImage ("Splashscreen.png") localGroup:insert(background) --> This sets the background local redbutton = display.newImage ("splashplay.png") redbutton.x = 160 redbutton.y = 100 localGroup:insert(redbutton) local bluebutton = display.newImage ("splashoptions.png") bluebutton.x = 160 bluebutton.y = 225 localGroup:insert(bluebutton) local yellowbutton = display.newImage ("splashabout.png") yellowbutton.x = 160 yellowbutton.y = 350 localGroup:insert(yellowbutton) --> This places our three buttons local function pressRed (event) if event.phase == "ended" then director:changeScene ("red") end end redbutton:addEventListener ("touch", pressRed) local function pressBlue (event) if event.phase == "ended" then director:changeScene ("blue") end end bluebutton:addEventListener ("touch", pressBlue) local function pressYellow (event) if event.phase == "ended" then director:changeScene ("yellow") end end yellowbutton:addEventListener ("touch", pressYellow) --> This adds the functions and listeners to each button |
i recommend you to download director class example
http://developer.anscamobile.com/code/director-class-10
and see how it works
actual syntax for changing scene is like,
director:changeScene("your lua file name","any effect")
when you download by above link you should have good idea
:)
when using director, we use director:changeScene ("blue") to change the scene.
blue is actually a file residing in the same folder (blue.lua).
You don't have to make any changes to the director.lua file.
the colors specified inside director.lua file is for showing the fading effect. It got nothing to do with the colors shown when u click the button.
Thanks for the replies. Do I call the .lua from the menu.lua? I'm a newbie at this so any example would be awesome.
Thanks again,
Andrew
hope this sample will help... this was written for a fellow developer in this forum to solve a problem he was facing...
main.lua
1 2 3 4 | director = require("director") local mainGroup = display.newGroup() mainGroup:insert(director.directorView) director:changeScene("loadtitlescreen") |
Thank you for the response.
Ok so I have:
main.lua
loadtitlescreen.lua
titlescreen.lua
gameboard.lua
director.lua
When I load main.lua in to the corona simulator I get an error message
"Director Class - ERROR"
"Director ERROR: Failed to execute function:0x19d7d5a0( params ) function on "loadtitlescreen'."
The screen is black except for the words "Go to title screen".
Getting Director to function properly seems to be my biggest hurdle. I'm really at a loss of what to do or where to go from here : (
Sorry there was a small error in loadtitlescreen.lua.
I edited something after posting and din't check whether its working or not... :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | module(..., package.seeall) function new() print ("in load titlescreen file") local localGroup = display.newGroup() local titlescreen = display.newText("Go to title screen",75,300,nil,25) localGroup:insert(titlescreen) local function touched (event) if ("ended" == event.phase) then director:changeScene( "titlescreen", "fade" ) end end titlescreen:addEventListener ("touch", touched) -- MUST return a display.newGroup() return localGroup end |
Thanks a million for checking back in. You really helped me out. Give yourself a pat on the back please : )
you are welcome....
I've got another question.
Here's my code for loadtitlescreen.lua
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | module(..., package.seeall) function new() print ("in load titlescreen file") local localGroup = display.newGroup() local background = display.newImage("splash.png" ) background.x = display.stageWidth / 2 background.y = display.stageHeight / 2 local titlescreen = display.newText("Play Game!",175,130,nil,25) localGroup:insert(titlescreen) titlescreen.x = display.stageWidth / 2 titlescreen.y = display.stageHeight / 2 local function touched (event) if ("ended" == event.phase) then director:changeScene( "titlescreen", "fade" ) end end titlescreen:addEventListener ("touch", touched) -- MUST return a display.newGroup() return localGroup end |
just add localGroup:insert(background) and it will be fine.
thanks again : )
I'm trying to make more groups but not having much luck, here's my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | local localGroup = display.newGroup() local titlescreen = display.newImage("Playbutton.png" ) localGroup:insert(titlescreen) titlescreen.x = display.stageWidth / 1.9 titlescreen.y = display.stageHeight / 2.1 local function touched (event) if ("ended" == event.phase) then director:changeScene( "titlescreen", "fade" ) end end titlescreen:addEventListener ("touch", touched) -- MUST return a display.newGroup() return localGroup end |
I din't understand what you are trying to achieve
if its just showing 2 buttons which takes you to 2 different screens then the below code will do
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | module(..., package.seeall) function new() local localGroup = display.newGroup() local playBTN = display.newImage("Playbutton.png" ) localGroup:insert(playBTN) playBTN.x = display.stageWidth / 1.9 playBTN.y = display.stageHeight / 2.1 local optionsBTN = display.newImage("optionsbutton.png" ) localGroup:insert(optionsBTN) optionsBTN.x = display.stageWidth / 1.9 optionsBTN.y = display.stageHeight / 2.1 local function playtouched (event) if ("ended" == event.phase) then director:changeScene( "titlescreen", "fade" ) end end local function Optionstouched (event) if ("ended" == event.phase) then director:changeScene( "optionsbutton", "fade" ) end end playBTN:addEventListener ("touch", playtouched) optionsBTN:addEventListener ("touch", Optionstouched) -- MUST return a display.newGroup() return localGroup end |
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
finding freelance / contract work
Coremidi support
READ_PHONE_STATE change?
Cavern Drake - First In-App Purchase Enabled App - Ready for Sale (FREE)
event.phase == "ended" is being missed during fast swipe and release
Who made this particle emitter? Can't find the thread/code exchange/url for it.
Director Class and Modules / external files
Not able to reauthorize Corona SDK on Mac
Game Edition Alpha 3 Is Now Available