I need help adding a start button to my game. My game uses storyboard. So I have a menu screen to begin with. Then a button on the menu screen takes the player to a another screen that has all the levels. When the player clicks on the level the game immediately starts which isn’t what I want. [import]uid: 6134 topic_id: 27610 reply_id: 327610[/import]
Just use a state machine.
I’ve read a few of your posts. I think you might find this page useful: http://learningcorona.com/ [import]uid: 108204 topic_id: 27610 reply_id: 112117[/import]
Can a use a State Machine when using storyboard to switch between screens ? I looked at that link and don’t see anything about state machine. Does it have a different name ? [import]uid: 6134 topic_id: 27610 reply_id: 112165[/import]
How about implementing a start button with ui.lua that appears when you tap on the game level (button.isVisible = true). Then tap the start button to start the game? [import]uid: 108204 topic_id: 27610 reply_id: 112176[/import]
State machines are a powerful concept. So here is a little more info:
http://en.wikipedia.org/wiki/Finite-state_machine
Which would go something like this (untested example)
local state = "none"
local function stateMachine(event)
if state == "menu" then
storyboard.gotoScene("menu")
state = "none" -- Reset state
elseif state == "game" then
storyboard.gotoScene("game")
state = "none" --Reset state
end
end
Runtime:addEventListener("enterFrame", stateMachine)
[import]uid: 84637 topic_id: 27610 reply_id: 112196[/import]
I am a bit confused so bare with with me. As said earlier I have a game that uses storyboard. In the Main.lua file I have it going to a menu.lua file via this code: firststoryboard.gotoScene(“menu”). Then I have a menu.lua file with several buttons. One button takes you to the level select screen: storyboard.gotoScene(“level”). Then in the level.lua files there are several buttons that the user can click on to choose a level to start from. So in this example lets say the user clicks on Level 1 button: storyboard.gotoScene(“level1”). When the users clicks on level1 button the game start right of the bat. It doesn’t give the user much time to react. Instead when the user clicks on level1 I want to add a button that the user clicks on to actually start the level. It can work without it but I might make users of my game very mad. So my question is how do I reference the code in level1.lua that actually allows me to add a start button.
local state = “none”
local function stateMachine(event)
if state == “menu” then
storyboard.gotoScene(“menu”)
state = “none” – Reset state
elseif state == “game” then
storyboard.gotoScene(“game”)
state = “none” --Reset state
end
end
Runtime:addEventListener(“enterFrame”, stateMachine) [import]uid: 6134 topic_id: 27610 reply_id: 112410[/import]
Create a state machine in level1.lua then. Change the state to say… “awaiting confirmation” when you tap on a level, and display a start button. Then change the state to “started” if you tap on the start button [import]uid: 108204 topic_id: 27610 reply_id: 112413[/import]