Question about Developer

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

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  

As you can tell I changed the images from background,red,blue,yellow.png

Director.lua

 elseif effect == "fade" then  
  
 local r, g, b  
 --  
 if type(arg1) == "nil" then  
 arg1 = "black"  
 end  
 --  
 if string.lower(arg1) == "red" then  
 r=255  
 g=0  
 b=0  
 elseif string.lower(arg1) == "green" then  
 r=0  
 g=255  
 b=0  
 elseif string.lower(arg1) == "blue" then  
 r=0  
 g=0  
 b=255  
 elseif string.lower(arg1) == "yellow" then  
 r=255  
 g=255  
 b=0  
 elseif string.lower(arg1) == "pink" then  
 r=255  
 g=0  
 b=255  
 elseif string.lower(arg1) == "white" then  
 r=255  
 g=255  
 b=255  
 elseif type (arg1) == "number"  
 and type (arg2) == "number"  
 and type (arg3) == "number" then  
 r=arg1  
 g=arg2  
 b=arg3  
 else  
 r=0  
 g=0  
 b=0  
 end  
 --  
 nextView.x = display.contentWidth  
 nextView.y = 0  
 --  
 loadScene (nextScene)  
 --  
 local fade = display.newRect( 0 - display.contentWidth, 0 - display.contentHeight, display.contentWidth \* 3, display.contentHeight \* 3 )  
 fade.alpha = 0  
 fade:setFillColor( r,g,b )  
 effectView:insert(fade)  
 --  
 showFx = transition.to ( fade, { alpha=1.0, time=fxTime } )  
 --  
 timer.performWithDelay( fxTime, fxEnded )  
 --  
 local function returnFade ( event )  
  
 showFx = transition.to ( fade, { alpha=0, time=fxTime } )  
 --  
 local function removeFade ( event )  
 fade:removeSelf()  
 end  
 --  
 timer.performWithDelay( fxTime, removeFade )  
  
 end  
 --  
 timer.performWithDelay( fxTime+1, returnFade )  

I realize that it will display colors when I click the buttons but how would you make the button direct you to say Level1.lua? So click = level1.lua

Sorry if this is a stupid question but I’m basically learning how to program by seeing the code and messing around with it. This however has left me stumped : (
Thanks for any help,
Andrew
[import]uid: 72845 topic_id: 12432 reply_id: 312432[/import]

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

:slight_smile: [import]uid: 12482 topic_id: 12432 reply_id: 45369[/import]

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.
[import]uid: 71210 topic_id: 12432 reply_id: 45372[/import]

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 [import]uid: 72845 topic_id: 12432 reply_id: 45627[/import]

hope this sample will help… this was written for a fellow developer in this forum to solve a problem he was facing…

main.lua
[lua]director = require(“director”)
local mainGroup = display.newGroup()
mainGroup:insert(director.directorView)
director:changeScene(“loadtitlescreen”)[/lua]

loadtitlescreen.lua
[lua]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

backbutton:addEventListener (“touch”, touched)

– MUST return a display.newGroup()
return localGroup
end[/lua]
titlescreen.lua
[lua]module(…, package.seeall)
local localGroup = display.newGroup()
local gameTXT = display.newText (“Go to Game”,100,240,nil,25)
localGroup:insert(gameTXT)

local function touchedInstructions (event)
if (“ended” == event.phase) then
director:changeScene (“gameboard”, “fade”)
end
end

gameTXT:addEventListener (“touch”, touchedInstructions)

function new()
– MUST return a display.newGroup()
print(“title screen”)
return localGroup
end[/lua]

gameboard.lua
[lua]module(…, package.seeall)

function new()
local localGroup2 = display.newGroup()

–local backbutton = display.newImage (“backbutton.png”)
local backbutton = display.newText(“back”,75,300,nil,25)
localGroup2:insert(backbutton)
local function touched (event)
if (“ended” == event.phase) then
director:changeScene( “titlescreen”, “fade” )
end
end

backbutton:addEventListener (“touch”, touched)

return localGroup2
end[/lua]
[import]uid: 71210 topic_id: 12432 reply_id: 45628[/import]

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 : ( [import]uid: 72845 topic_id: 12432 reply_id: 45675[/import]

Sorry there was a small error in loadtitlescreen.lua.
I edited something after posting and din’t check whether its working or not… :slight_smile:

[lua]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[/lua] [import]uid: 71210 topic_id: 12432 reply_id: 45708[/import]

Thanks a million for checking back in. You really helped me out. Give yourself a pat on the back please : ) [import]uid: 72845 topic_id: 12432 reply_id: 45721[/import]

you are welcome… [import]uid: 71210 topic_id: 12432 reply_id: 45722[/import]

I’ve got another question.

Here’s my code for loadtitlescreen.lua

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  

How come when I add a background image I no longer get prompted to “Play Game!”? However if I remove:

 local background = display.newImage("splash.png" )  
 background.x = display.stageWidth / 2  
 background.y = display.stageHeight / 2   

The “Play Game!” text is displayed and everything works just fine. [import]uid: 72845 topic_id: 12432 reply_id: 45808[/import]

just add localGroup:insert(background) and it will be fine. [import]uid: 71210 topic_id: 12432 reply_id: 45845[/import]

thanks again : ) [import]uid: 72845 topic_id: 12432 reply_id: 45974[/import]

I’m trying to make more groups but not having much luck, here’s my code:

 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 need to rename some things but when I click my play button it loads the titlescreen (in this case level 1)

I’ve tried to create another group using this:

 local localGroup2 = display.newGroup2()  
 local titlescreen = display.newImage("optionsbutton.png" )  
 localGroup:insert(optionsbutton)  
  
optionsbutton.x = display.stageWidth / 1.9  
optionsbutton.y = display.stageHeight / 2.1   
 local function touched (event)  
 if ("ended" == event.phase) then  
 director:changeScene( "optionsbutton", "fade" )   
 end   
 end  
   
 optionsbutton:addEventListener ("touch", touched)  
   
 -- MUST return a display.newGroup2()  
 return localGroup2  
end  

I’ve also created a .lua to get called when the button is pressed. Not sure what I’m doing wrong as this is my first time trying to make multiple groups. Any help would be appreciated.

Thanks,
Andrew [import]uid: 72845 topic_id: 12432 reply_id: 46242[/import]

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
[lua]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[/lua]

you don’t have to create 2 groups for 2 buttons… each director scene need to return only one group…all buttons on that scene need to be inserted in to that group. [import]uid: 71210 topic_id: 12432 reply_id: 46333[/import]