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