Dears,
I am trying to make a game that is about questions and 4 answers.
the menu screen contains 2 buttons
1st is to start the game.
2nd is options buttons.
once i add the buttons to the sceneGroup they disappear.
the reason to add them is to disappear once the user moved the next scene.
what is wrong with my code? i have been trying for 2 days.
the only thing can come to my mind is to selfkill thos buttons once moved to the next scene.
the code:
local composer = require( “composer” )
local scene = composer.newScene()
– All code outside of the listener functions will only be executed ONCE unless “composer.removeScene()” is called
– Local forward references should go here
local function tapped(event)
local id = event.target.id
if id == “Start” then
composer.gotoScene( “Level1”, {effect = “slideDown”} )
print(“Level 1”)
else
composer.gotoScene( “About_Us”, {effect = “slideDown”} )
print(“about us”)
end
end
– “scene:create()”
function scene:create( event )
local widget = require( “widget”)
local sceneGroup = self.view
– Initialize the scene here
– Example: add display objects to “sceneGroup”, add touch listeners, etc.
--local title = display.newText( “abed” , centerX, centerY ,“Helvetica”, 20 )
------------------------------------------start
startButton = widget.newButton {
id = “Start”,
onRelease = tapped,
defaultFile = “button.png”,
overFile = “buttonclicked.png”,
label = “إبدأ اللعبة”,
labelColor = { default={ 1, 1, 1 } }
}
startButton.x=centerX
startButton.y = centerY±50
–sceneGroup:insert( startButton )
------------------------------------------options
optionbutton = widget.newButton {
id = “options”,
onRelease = tapped,
defaultFile = “button.png”,
overFile = “buttonclicked.png”,
label = “خيارات”,
labelColor = { default={ 1, 1, 1 } }
}
optionbutton.x=centerX
optionbutton.y = centerY+50
–sceneGroup:insert( optionbutton )
–local start = display.newImageRect( [parent,], filename, [baseDir,], width, height )
end
– “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Called when the scene is still off screen (but is about to come on screen)
elseif ( phase == “did” ) then
-------------------------------------------code
end
end
– “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Called when the scene is on screen (but is about to go off screen)
– Insert code here to “pause” the scene
– Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == “did” ) then
– Called immediately after scene goes off screen
end
end
– “scene:destroy()”
function scene:destroy( event )
local sceneGroup = self.view
– Called prior to the removal of scene’s view
– Insert code here to clean up the scene
– Example: remove display objects, save state, etc.
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene