Start Menu and Game Structure

Hi.

I want to port a game to corona, but I’m very confused.

The game presents a start menu with some graphics, level select (+ button, - button), an exit button and a start button.

How to structure that?

I made something like that:

main.lua

=======

–initiate global variables

level=1

stay=1

function startmenu()

    local buttonstart=nil
    local buttonexit=nil

    local buttonminus = display.newImage(“buttonminus.png”)
    buttonminus.x = -500
    buttonminus.y = 410
    local buttonplus = display.newImage(“buttonplus.png”)
    buttonplus.x = -500
    buttonplus.y = 410

    
    local function drawmenu()
        local filepng=“txt”
        local dig1=0
        local dig2=0

        – display backgroun image
        display.newImage(“background.png”,0,0)

        – display game title
        display.newImage(“title.png”, (largura - 540)/2, 20)

        — display the “LEVEL” word
        display.newImage(“txtlevel.png”,80,370)

       – display exit button
        buttonexit=display.newImage(“buttonexit.png”,782,0)

       — display level digits

        if level<10 then
            filepng = “txt” … level … “.png”
            display.newImage(filepng, 320, 370)
        else
            dig1=math.floor(level/10)
            dig2=level - (10*dig1)
            filepng = “txt” … dig1 … “.png”
            display.newImage(filepng, 320, 370)
            filepng = “txt” … dig2 … “.png”
            display.newImage(filepng, 356, 370)
        end

        — draw minus level button, if level > 1
        if nivel>1 then
            buttonminus.x=45
        else
            buttonminus.x=-500
        end

        – draw plus level button, if level < 20 (there are 20 level in the game, 20 is the last level)
        if nivel<20 then
            if nivel<10 then

                – if there are only 1 digit in level number
                buttonplus.x=399
            else

                – if there are 2 digit in level number
                buttonplus.x=435
            end
        else

            – positionate out of screen if level=20 (last), so don’t use
            buttonplus.x=-500
        end

        --display start button
        buttonstart=display.newImage(“botstart.png”,147,270)

    end

    drawmenu()

    local function levelminus()
        level=level-1
        drawmenu()
        return true
    end

    local function levelplus()
        level=level+1
        drawmenu()
        return true
    end

    local function startbut()

        stay=0
        return true
    end

    if level>1 then
        buttonminus:addEventListener( “tap”, levelminus )
    end

    if nivel<20 then
        buttonplus:addEventListener( “tap”, levelplus )
    end

    buttonstart:addEventListener( “tap”, startbut )

end

startmenu()

if stay=0 then

     – go to game itself

end

====================

so…

This is the correct structure?

when I press the start button, I want to exit startmenu and go to another new thing - the game itself, so how do I cancel the evenListerners and remove everything?

Anyway, the starmenu does not show the buttonminus and buttonplus. Why?

And if I write something in the “if stay=0 then” near to end of main.lua, like display.newImage(“something.png”,0,0)

and press the start button, so --> the variable stay will be 0. but the code doesn’t run, and it does not show the image something.png.

I made that thing to test if when I press start button, I could go to another thing… the game itself.

PLEASE help me

Hi @galiksoft.  Welcome to Corona SDK’s forums.  Before I look at your question, please be aware that we have forum rules that request that you only post your question once in one forum and not double post.  I’ve deleted your other post.  The community will find your post here.

You need to learn how to use the storyboard.* API calls.  Storyboard allows you to structure your different scenes in separate .lua files, where you can have a menu.lua that would have your buttons and when the buttons are pressed, you can start the game and do what you need to do. 

Start here:  http://www.coronalabs.com/resources/tutorials/user-interface-scenes-and-widgets/

Hi @galiksoft.  Welcome to Corona SDK’s forums.  Before I look at your question, please be aware that we have forum rules that request that you only post your question once in one forum and not double post.  I’ve deleted your other post.  The community will find your post here.

You need to learn how to use the storyboard.* API calls.  Storyboard allows you to structure your different scenes in separate .lua files, where you can have a menu.lua that would have your buttons and when the buttons are pressed, you can start the game and do what you need to do. 

Start here:  http://www.coronalabs.com/resources/tutorials/user-interface-scenes-and-widgets/