I have tried to make a button. This button once clicked should redirect you to another scene.
The problem is that it doesn’t work. It appear but I can’t click on it.
I will let the file here for a better understanding.
–
– over.lua
–
local composer = require( “composer” )
local scene = composer.newScene()
– include Corona’s “physics” library
local widget = require “widget”
– forward declarations and other locals
local screenW, screenH, halfW = display.actualContentWidth, display.actualContentHeight, display.contentCenterX
local menuBtn
local function onmenuBtnRelease()
composer.gotoScene( “menu”, “fade”, 500 )
return true – indicates successful touch
end
function scene:create( event )
– e.g. add display objects to ‘sceneGroup’, add touch listeners, etc.
local sceneGroup = self.view
– We need physics started to add bodies, but we don’t want the simulaton
– running until the scene is on the screen.
physics.start()
physics.pause()
– background at the real top, left corner.
local background = display.newImageRect( “over.png”, display.actualContentWidth, display.actualContentHeight )
background.anchorX = 0
background.anchorY = 0
background.x = 0 + display.screenOriginX
background.y = 0 + display.screenOriginY
menuBtn = widget.newButton{
defaultFile=“menu.png”,
width=200,
height=80,
onRelease = onmenuBtnRelease-- event listener function
}
menuBtn.x = display.contentCenterX -195
menuBtn.y = display.contentHeight - 50
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == “will” then
– Called when the scene is still off screen and is about to move on screen
elseif phase == “did” then
– Called when the scene is now on screen
–
– INSERT code here to make the scene come alive
– e.g. start timers, begin animation, play audio, etc.
physics.start()
end
end
function scene:hide( event )
local sceneGroup = self.view
if event.phase == “will” then
– e.g. stop timers, stop animation, unload sounds, etc.)
physics.stop()
elseif phase == “did” then
– Called when the scene is now off screen
end
end
function scene:destroy( event )
– e.g. remove display objects, remove touch listeners, save state, etc.
local sceneGroup = self.view
package.loaded[physics] = nil
physics = nil
if menuBtn then
menuBtn:removeSelf() – widgets must be manually removed
menuBtn = nil
end
end
– Sunet
local startSound = audio.loadSound( “hajime.wav” )
local laserChannel = audio.play( startSound, { channel=2 } )
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene