Does anyone know or have a link to a tutorial on how I can make a level selection for my game. [import]uid: 134147 topic_id: 24239 reply_id: 324239[/import]
There is nothing specific for level selection screens. What I’d advice you to do is take a look at storyboard first, for the scene management.
After that everything becomes a little more clear. For example, you could use one scene to display all the levels. Then, depending on what level/number the user taps on, using a global flag you could construct the level in the next scene.
Edit: Found this for you - http://www.newnams.com/corona-level-selection-tutorial/
For other tutorials, browse this site: http://www.learningcorona.com/ - It contains tutorials for almost anything
[import]uid: 14018 topic_id: 24239 reply_id: 97922[/import]
I can’t get the World button and level 1 button to remove when the actual game has started. The world & lvl 1 button runs in the background. -.- [import]uid: 134147 topic_id: 24239 reply_id: 97933[/import]
Hi speedy-boy,
Make sure you add the buttons to the display group when you create them. If you don’t, they won’t be removed when you change scenes.
Mark [import]uid: 117098 topic_id: 24239 reply_id: 97981[/import]
Can you post your code? [import]uid: 14018 topic_id: 24239 reply_id: 97982[/import]
My main.lua leads to —> menu.lua which leads to —> Worlds.lua
–
– worlds.lua
local storyboard = require( “storyboard” )
local widget = require “widget”
local buttonGroup = display.newGroup()
local scene = storyboard.newScene()
local worldPage = 0
local maxWorlds = 6
local movingScreen = false
– Table to hold world buttons
local worlds = {}
local function backgroundTouch(event)
if (event.phase==“ended”) then
movingScreen=false
end
if (event.phase==“moved” and movingScreen==false) then
local delta = event.xStart - event.x
if (delta < -10 and worldPage>0) then
movingScreen=true
worldPage = worldPage -1
buttonGroup:translate(320, 0)
end
if (delta > 10 and worldPage movingScreen=true
worldPage = worldPage + 1
buttonGroup:translate(-320, 0)
end
end
return true
end
– ‘onRelease’ event listener for buttons
local function buttontouch(event)
if (event.phase==“release”) then
movingScreen=false
storyboard.world = event.target.id – Save the selected world
storyboard.gotoScene( “levels”, “fade”, 500 ) – go to levels scene
end
return true – indicates successful touch
end
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
local background = display.newImageRect( “background.png”, display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
background:addEventListener(“touch”,backgroundTouch)
group:insert(background)
group:insert(buttonGroup)
– create three widget buttons to select the game world
for i=1,maxWorlds do
worlds[i] = widget.newButton{
label="World "…i,
default = “button2.png”,
id=i,
width=128, height=128,
onEvent = buttontouch – event listener function
}
worlds[i].x = (i145) + (i % 2)20
worlds[i].y = display.contentHeight * 0.5
– If you are using the last publicly available version of Corona, you may
– need to replace the following line with:
– group:insert( worlds[i].view )
buttonGroup:insert( worlds[i] )
end
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
– INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end
– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
for i=#worlds, 1, -1 do
if worlds[i] then
worlds[i]:removeSelf() – widgets must be manually removed
worlds[i] = nil
end
end
end
-----------------------------------------------------------------------------------------
– END OF YOUR IMPLEMENTATION
-----------------------------------------------------------------------------------------
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
-----------------------------------------------------------------------------------------
return scene
Which leads to the levels.lua
-----------------------------------------------------------------------------------------
–
– levels.lua
–
-----------------------------------------------------------------------------------------
local storyboard = require( “storyboard” )
local widget = require "widget"
local scene = storyboard.newScene()
– Table to hold level buttons
local levels = {}
– ‘onRelease’ event listener for playBtn
local function buttonRelease(event)
storyboard.level = event.target.id
– go to level1 scene
storyboard.gotoScene( “level1”)
return true – indicates successful touch
end
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
local background = display.newImageRect( “background.png”, display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
group:insert(background)
– create 20 buttons to choose the level
for i=0,3 do
for j=1,5 do
current = i5 + j – This calculates the current position in the table
levels[current] = widget.newButton{
label=current,
id=current,
default = “button2.png”,
width=64, height=64,
onRelease = buttonRelease – event listener function
}
levels[current].x = 10 + (j65)
levels[current].y = 60+ (i*65)
– If you are using the last publicly available version of Corona, you may
– need to replace the following line with:
– group:insert( levels[current].view )
group:insert( levels[current] )
end
end
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
– INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end
– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
for i=#levels,1,-1 do
if levels[i] then
levels[i]:removeSelf() – widgets must be manually removed
levels[i] = nil
end
end
end
-----------------------------------------------------------------------------------------
– END OF YOUR IMPLEMENTATION
-----------------------------------------------------------------------------------------
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
-----------------------------------------------------------------------------------------
return scene
then leads to my level1.
When it loads the lvl 1, i can still press the world and level 1 button, its all messy. If i press it its like im running multiple scenes at a time <.>Hope I explained it well enough.
thanks [import]uid: 134147 topic_id: 24239 reply_id: 97992[/import] </.>