Hi all,
I have implemented the code from corona SDK regarding to the physics. I have added the code for hearing the sound , but when i click the play button it hears the sound but not the going to the scene,
please help me to correct it,
I want to hear the sound when click the play it will hear the sound and then go to scene.
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
– include Corona’s “widget” library
local widget = require “widget”
– adding sound
local clickSound = audio.loadSound ( “media/click.WAV” )
– forward declarations and other locals
local playBtn
– ‘onRelease’ event listener for playBtn
local function onPlayBtnRelease()
– go to level1.lua scene
storyboard.gotoScene( “level1”, “fade”, 500 )
return true – indicates successful touch
end
– BEGINNING OF YOUR IMPLEMENTATION
–
– NOTE: Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
–
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
– display a background image
local background = display.newImageRect( “gfx/dropMeLogo.png”, display.contentWidth, display.contentHeight )
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 0, 0
– create/position logo/title image on upper-half of the screen
local titleLogo = display.newImageRect( “gfx/corodoLogo.png”, 264, 42 )
titleLogo.x = display.contentWidth * 0.5
titleLogo.y = 50
– create a widget button (which will loads level1.lua on release)
playBtn = widget.newButton{
label=“Play”,
labelColor = { default={255}, over={128} },
default=“gfx/btnPlay.png”,
over=“button-over.png”,
width=154, height=40,
onRelease = onPlayBtnRelease – event listener function
}
playBtn.x = display.contentWidth*0.5
playBtn.y = display.contentHeight - 100
btnScore = widget.newButton{
label=“Score”,
labelColor = { default={255}, over={128} },
default=“gfx/btnPlay.png”,
over=“button-over.png”,
width=154, height=40,
onRelease = onPlayBtnRelease – event listener function
}
btnScore.x = display.contentWidth*0.5
btnScore.y = display.contentHeight - 70
btnShare = widget.newButton{
label=“Share”,
labelColor = { default={255}, over={128} },
default=“gfx/btnPlay.png”,
over=“button-over.png”,
width=154, height=40,
onRelease = onPlayBtnRelease – event listener function
}
btnShare.x = display.contentWidth*0.5
btnShare.y = display.contentHeight - 40
– all display objects must be inserted into group
group:insert( background )
group:insert( titleLogo )
group:insert( playBtn )
group:insert( btnScore )
group:insert( btnShare )
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.)
– adding sound
function playBtn:touch (e)
if e.phase == “began” then
audio.play (clickSound)
end
end
playBtn:addEventListener ( “touch”, playBtn )
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
if playBtn then
playBtn:removeSelf() – widgets must be manually removed
playBtn = nil
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