help with the screen menu how?

i want to make simple menu screen with a play button this is my code (i don’t now how i am very newbie)

[code]
o = 0;
time_remain = 10;
time_up = false;
ready = false;
total_balls = 16
–set walpaper
background = display.newImage(“poro.jpg”)
background.y = display.contentHeight/2

–set music
local pop_sound = audio.loadSound(“pop.mp3”);
local win_sound = audio.loadSound(“win.mp3”);
local fail_sound = audio.loadSound(“fail.mp3”);
local soundtrack = audio.loadStream(“soundtrack.mp3”);

local display_txt = display.newText(“Wait”, 0, 0, native.sistemFont, 16*2);
display_txt.xScale = .5; display_txt.yScale = .5;
display_txt:setReferencePoint(display.bottomLeftReferencePoint);
display_txt.x = 20; display_txt.y = display.contentHeight-20;

local countdowntxt = display.newText(time_remain, 0, 0, native.systemFont, 16*2);
countdowntxt.xScale = .5; countdowntxt.yScale = .5 ;
countdowntxt:setReferencePoint(display.BottomRigthReferencePoint) ;
countdowntxt.x = display.contentWidth-20; countdowntxt.y = display.contentHeight-20;

– add physics engine, start up the engine, and apply gravity
local physics = require(“physics”)
physics.start()
– Set gravity to act “down” (ie, toward the bottom of the device )
physics.setGravity (1, 30 )

–set wally image and position
local wally = display.newImage(“bara5.png”)
wally.x = display.contentWidth/1
–turn wally into physics body
physics.addBody(wally,“static”,{bounce = 2})

– pendejo
local pendejo = display.newImage(“pinipon.png”)
pendejo.y = display.contentHeight/2
pendejo.x = display.contentWidth/4.5
physics.addBody(pendejo,“static”)
local function animate( event )
pendejo.rotation = pendejo.rotation + 4
end
Runtime:addEventListener( “enterFrame”,animate );

–add floor image and position
local floor = display.newImage(“bar.png”)
floor.y = display.contentHeight/1
– turn floor into physics body
physics.addBody(floor,“static”)

local function trackBalls(obj)
obj:removeSelf()
o = o-1

if(time_up ~= true) then

if(o == 0) then
audio.play(win_sound)
timer.cancel(gametmr)
display_txt.text = “WIN!”
end
end
end

local function countDown(event)
if(time_remain == 10) then
ready = true
display_txt.text = “Go!”
audio.play(soundtrack, {loops =-1})
end
time_remain = time_remain-1
countdowntxt.text = time_remain

if(time_remain == 0) then
time_up = true

if(o ~= 0) then
audio.play(fail_sound)
display_txt.text = “FAIL”
ready = false
end
end
end

–set ball to stage and position
local function spawnBall()
local ball =display.newImage(“coconut copia.png”)
ball.x = math.random ( 320 )
ball.y = -100

–set wall image and position
local wall= display.newImage(“bara5.png”)
wall.x = display.contentWidth/102
–turn wall into physics body
physics.addBody(wall,“static”)

– turn ball into physics body
physics.addBody(ball,{bounce = 0 } )

function ball:touch(e)
if(ready == true ) then
if(e.phase == “ended”) then
–play pop
audio.play(pop_sound)
–remove the balls
trackBalls(self);
end
end

return true;

end
–increment o for every ball created
o = o+1;

ball:addEventListener(“touch”, ball) ;

–if all balls created, start the game timer
if(o == total_balls) then
gametmr = timer.performWithDelay(850, countDown, 10 );
else
ready = false;

end

end

timer.performWithDelay( 100,spawnBall,total_balls)
[import]uid: 179948 topic_id: 31893 reply_id: 331893[/import]

Hi there,

Am I correct in thinking the above code is your game and you want a menu screen to led onto it?

You should look into using the storyboard.

A basic example would be to save the above as gameScreen.lua and have a main.lua like this:

[lua]-- tells corona to use the storyboard api
local storyboard = require “storyboard”

– changes scene when called
function startGame()
playButton:removeSelf()
storyboard.gotoScene( “gameScene” )
end

– create some text and make it listen for tap’s
playButton = display.newText(“hello”,(display.contentWidth/2),(display.contentHeight/2), native.systemFont, 50)
playButton:setTextColor(255, 255, 255)
playButton.text = “Play Game”
playButton:addEventListener(“tap”, startGame)[/lua] [import]uid: 62706 topic_id: 31893 reply_id: 127208[/import]

look thanks i do this, but doesn’t work perfect because when i touch the button to start the game didn’t start this is my code [code]

function main()
mainMenu()
end
function loadGame(event)
if event.target.name == “playbutton” then
transition.to(menuScreenGroup,{time = 0, alpha=0, onComplete =
addGameScreen})
playBtn:removeEventListener(“tap”, loadGame)
end
end

menuScreenGroup = display.newGroup()
mmScreen = display.newImage(“poro.jpg”, 0, 0, true)
mmScreen.x = _W
mmScreen.y = _H
playBtn = display.newImage(“default.png”)
playBtn:setReferencePoint(display.CenterReferencePoint)
playBtn.x = _W+50; playBtn.y = _H +50
playBtn.name = “playbutton”
menuScreenGroup:insert(mmScreen)
menuScreenGroup:insert(playBtn)
o = 0;
time_remain = 10;
time_up = false;
ready = false;
total_balls = 16
function addGameScreen()

–set music
local pop_sound = audio.loadSound(“pop.mp3”);
local win_sound = audio.loadSound(“win.mp3”);
local fail_sound = audio.loadSound(“fail.mp3”);
local soundtrack = audio.loadStream(“soundtrack.mp3”);

local display_txt = display.newText(“Wait”, 0, 0, native.sistemFont, 16*2);
display_txt.xScale = .5; display_txt.yScale = .5;
display_txt:setReferencePoint(display.bottomLeftReferencePoint);
display_txt.x = 20; display_txt.y = display.contentHeight-20;

local countdowntxt = display.newText(time_remain, 0, 0, native.systemFont, 16*2);
countdowntxt.xScale = .5; countdowntxt.yScale = .5 ;
countdowntxt:setReferencePoint(display.BottomRigthReferencePoint) ;
countdowntxt.x = display.contentWidth-20; countdowntxt.y = display.contentHeight-20;

– add physics engine, start up the engine, and apply gravity
local physics = require(“physics”)
physics.start()
– Set gravity to act “down” (ie, toward the bottom of the device )
physics.setGravity (1, 30 )

–set wally image and position
local wally = display.newImage(“bara5.png”)
wally.x = display.contentWidth/1
–turn wally into physics body
physics.addBody(wally,“static”,{bounce = 2})

– pendejo
local pendejo = display.newImage(“pinipon.png”)
pendejo.y = display.contentHeight/2
pendejo.x = display.contentWidth/4.5
physics.addBody(pendejo,“static”)
local function animate( event )
pendejo.rotation = pendejo.rotation + 4
end
Runtime:addEventListener( “enterFrame”,animate );

–add floor image and position
local floor = display.newImage(“bar.png”)
floor.y = display.contentHeight/1
– turn floor into physics body
physics.addBody(floor,“static”)

local function trackBalls(obj)
obj:removeSelf()
o = o-1

if(time_up ~= true) then

if(o == 0) then
audio.play(win_sound)
timer.cancel(gametmr)
display_txt.text = “WIN!”
end
end
end

local function countDown(event)
if(time_remain == 10) then
ready = true
display_txt.text = “Go!”
audio.play(soundtrack, {loops =-1})
end
time_remain = time_remain-1
countdowntxt.text = time_remain

if(time_remain == 0) then
time_up = true

if(o ~= 0) then
audio.play(fail_sound)
display_txt.text = “FAIL”
ready = false
end
end
end

–set ball to stage and position
local function spawnBall()
local ball =display.newImage(“coconut copia.png”)
ball.x = math.random ( 320 )
ball.y = -100

–set wall image and position
local wall= display.newImage(“bara5.png”)
wall.x = display.contentWidth/102
–turn wall into physics body
physics.addBody(wall,“static”)

– turn ball into physics body
physics.addBody(ball,{bounce = 0 } )

function ball:touch(e)
if(ready == true ) then
if(e.phase == “ended”) then
–play pop
audio.play(pop_sound)
–remove the balls
trackBalls(self);
end
end

return true;

end
–increment o for every ball created
o = o+1;

ball:addEventListener(“touch”, ball) ;

–if all balls created, start the game timer
if(o == total_balls) then
gametmr = timer.performWithDelay(850, countDown, 10 );
else
ready = false;

end

end

end
timer.performWithDelay( 100,spawnBall,total_balls)
[import]uid: 179948 topic_id: 31893 reply_id: 127214[/import]

Hi there,

Am I correct in thinking the above code is your game and you want a menu screen to led onto it?

You should look into using the storyboard.

A basic example would be to save the above as gameScreen.lua and have a main.lua like this:

[lua]-- tells corona to use the storyboard api
local storyboard = require “storyboard”

– changes scene when called
function startGame()
playButton:removeSelf()
storyboard.gotoScene( “gameScene” )
end

– create some text and make it listen for tap’s
playButton = display.newText(“hello”,(display.contentWidth/2),(display.contentHeight/2), native.systemFont, 50)
playButton:setTextColor(255, 255, 255)
playButton.text = “Play Game”
playButton:addEventListener(“tap”, startGame)[/lua] [import]uid: 62706 topic_id: 31893 reply_id: 127208[/import]

look thanks i do this, but doesn’t work perfect because when i touch the button to start the game didn’t start this is my code [code]

function main()
mainMenu()
end
function loadGame(event)
if event.target.name == “playbutton” then
transition.to(menuScreenGroup,{time = 0, alpha=0, onComplete =
addGameScreen})
playBtn:removeEventListener(“tap”, loadGame)
end
end

menuScreenGroup = display.newGroup()
mmScreen = display.newImage(“poro.jpg”, 0, 0, true)
mmScreen.x = _W
mmScreen.y = _H
playBtn = display.newImage(“default.png”)
playBtn:setReferencePoint(display.CenterReferencePoint)
playBtn.x = _W+50; playBtn.y = _H +50
playBtn.name = “playbutton”
menuScreenGroup:insert(mmScreen)
menuScreenGroup:insert(playBtn)
o = 0;
time_remain = 10;
time_up = false;
ready = false;
total_balls = 16
function addGameScreen()

–set music
local pop_sound = audio.loadSound(“pop.mp3”);
local win_sound = audio.loadSound(“win.mp3”);
local fail_sound = audio.loadSound(“fail.mp3”);
local soundtrack = audio.loadStream(“soundtrack.mp3”);

local display_txt = display.newText(“Wait”, 0, 0, native.sistemFont, 16*2);
display_txt.xScale = .5; display_txt.yScale = .5;
display_txt:setReferencePoint(display.bottomLeftReferencePoint);
display_txt.x = 20; display_txt.y = display.contentHeight-20;

local countdowntxt = display.newText(time_remain, 0, 0, native.systemFont, 16*2);
countdowntxt.xScale = .5; countdowntxt.yScale = .5 ;
countdowntxt:setReferencePoint(display.BottomRigthReferencePoint) ;
countdowntxt.x = display.contentWidth-20; countdowntxt.y = display.contentHeight-20;

– add physics engine, start up the engine, and apply gravity
local physics = require(“physics”)
physics.start()
– Set gravity to act “down” (ie, toward the bottom of the device )
physics.setGravity (1, 30 )

–set wally image and position
local wally = display.newImage(“bara5.png”)
wally.x = display.contentWidth/1
–turn wally into physics body
physics.addBody(wally,“static”,{bounce = 2})

– pendejo
local pendejo = display.newImage(“pinipon.png”)
pendejo.y = display.contentHeight/2
pendejo.x = display.contentWidth/4.5
physics.addBody(pendejo,“static”)
local function animate( event )
pendejo.rotation = pendejo.rotation + 4
end
Runtime:addEventListener( “enterFrame”,animate );

–add floor image and position
local floor = display.newImage(“bar.png”)
floor.y = display.contentHeight/1
– turn floor into physics body
physics.addBody(floor,“static”)

local function trackBalls(obj)
obj:removeSelf()
o = o-1

if(time_up ~= true) then

if(o == 0) then
audio.play(win_sound)
timer.cancel(gametmr)
display_txt.text = “WIN!”
end
end
end

local function countDown(event)
if(time_remain == 10) then
ready = true
display_txt.text = “Go!”
audio.play(soundtrack, {loops =-1})
end
time_remain = time_remain-1
countdowntxt.text = time_remain

if(time_remain == 0) then
time_up = true

if(o ~= 0) then
audio.play(fail_sound)
display_txt.text = “FAIL”
ready = false
end
end
end

–set ball to stage and position
local function spawnBall()
local ball =display.newImage(“coconut copia.png”)
ball.x = math.random ( 320 )
ball.y = -100

–set wall image and position
local wall= display.newImage(“bara5.png”)
wall.x = display.contentWidth/102
–turn wall into physics body
physics.addBody(wall,“static”)

– turn ball into physics body
physics.addBody(ball,{bounce = 0 } )

function ball:touch(e)
if(ready == true ) then
if(e.phase == “ended”) then
–play pop
audio.play(pop_sound)
–remove the balls
trackBalls(self);
end
end

return true;

end
–increment o for every ball created
o = o+1;

ball:addEventListener(“touch”, ball) ;

–if all balls created, start the game timer
if(o == total_balls) then
gametmr = timer.performWithDelay(850, countDown, 10 );
else
ready = false;

end

end

end
timer.performWithDelay( 100,spawnBall,total_balls)
[import]uid: 179948 topic_id: 31893 reply_id: 127214[/import]