Jelr ThirtyNine
Jelr ThirtyNine

Reputation: 1

Corona SDK Ui Button for Main Menu

I'm kinda new in using Corona SDK and I'm having a little problem on my main menu buttons. Whenever I press the buttons, it doesn't move or change the view; the buttons just disappear in the title screen.

module(..., package.seeall)

local ui = require ("ui")
local ui = require ("director")

local assetPath = "assets/"

local mainGroup = display.newGroup()

function new(params)
    local titleScreen = display.newImageRect(assetPath .. "Law of Magic.jpg", 
        display.contentWidth, display.contentHeight)
    titleScreen.x = display.contentWidth / 2
    titleScreen.y = 265
    mainGroup:insert(titleScreen)
    director:changeScene("titleScreen")

    local newgame = ui.newButton{ default = assetPath .. "new game.png", 
        onRelease = function(event)  director:changeScene("New game") end,}
    newgame.x = display.contentWidth / 2
    newgame.y = 445
    mainGroup:insert(newgame)

    local continue = ui.newButton{ default = assetPath .. "continue.png", 
        onRelease = function(event)  director:changeScene("Continue") end,}
    continue.x = display.contentWidth / 2
    continue.y = 447
    mainGroup:insert(continue)

    local option = ui.newButton{ default = assetPath .. "option.png", 
        onRelease = function(event)  director:changeScene("Option") end,}
    option.x = display.contentWidth / 2
    option.y = 449
    mainGroup:insert(option)

    local help = ui.newButton{ default = assetPath .. "help.png", 
        onRelease = function(event)  director:changeScene("Help") end,}
    help.x = display.contentWidth / 2
    help.y = 451
    mainGroup:insert(help)

    local exitgame = ui.newButton{ default = assetPath .. "exit game.png", 
        onRelease = function(event)  director:changeScene("Exit game") end,}
    exitgame.x = display.contentWidth / 2
    exitgame.y = 453
    mainGroup:insert(exitgame)

    return mainGroup
end

Upvotes: 0

Views: 1750

Answers (3)

Fazil Mir
Fazil Mir

Reputation: 833

Change this line

local ui = require ("director")

to

local director = require ("director")

And yeah make sure the file names are correct.

Upvotes: 0

Rob Miracle
Rob Miracle

Reputation: 3063

Also for this: director:changeScene("New game")

It's going to try and go to a scene, you are putting the name of the scene file. In this case, it's looking for a file called:

New Game.lua

in the same folder as your main.lua file. I personally would avoid filenames with spaces in them, and while the simulator isn't case sensitive, devices are and you have to make sure the filenames case matches what you are coding.

Also I'm concerned about this line: director:changeScene("titleScreen")

It would try to change scenes before you ever get to setting up your buttons.

Upvotes: 0

user1937554
user1937554

Reputation: 21

First I see you declare local ui two times.

Second you should use storyboard since it is supported by corona and you are new to coronaSDk

Upvotes: 2

Related Questions