0
votes

My buttons wont appear on the screen for some reason in Corona SDK here is my code what am I missing?

local composer = require( "composer" )

local scene = composer.newScene()

-- include Corona's "widget" library local widget = require "widget"

-- Function to handle button events local function handleButtonEvent( event )

if ( "ended" == event.phase ) then
    print( "Button was pressed and released" )
end

end


-- forward declarations and other locals local playBtn

-- 'onRelease' event listener for playBtn local function onPlayBtnRelease()

-- go to levelSelect.lua scene
composer.gotoScene( "levelSelect", "fade", 500 )

return true -- indicates successful touch

end

-- Background local sky = display.newImage ("startScreen/sky.png") sky.x = display.contentWidth/2; sky.y = display.contentHeight/2;

-- Picture local preston = display.newImage ("startScreen/PrestonArt.png") preston:scale( 0.4, 0.4 ) preston.x = display.contentWidth/2; preston.y = display.contentHeight/2;

-- Labels local learningLabel = display.newImage ("startScreen/Learning.png") learningLabel:scale( 0.3, 0.3 ) learningLabel.x = 506; learningLabel.y = 170;

local centerLabel = display.newImage ("startScreen/Center.png") centerLabel:scale( 0.3, 0.3 ) centerLabel.x = 506; centerLabel.y = 600;

function scene:create( event ) local sceneGroup = self.view

-- Called when the scene's view does not exist.
-- 
-- INSERT code here to initialize the scene
-- e.g. add display objects to 'sceneGroup', add touch listeners, etc.

-- create a widget button (which will loads levelSelect.lua on release)
playBtn = widget.newButton{
    defaultFile = "startScreen/Play.png",       --the "default" image file
    overFile = "startScreen/Play-Over.png",     --the "over" image file 
    width=240, height=120,
    onRelease = onPlayBtnRelease    -- event listener function
}
playBtn.x = 300; playBtn.y = 695;

-- all display objects must be inserted into group
 sceneGroup:insert( playBtn )

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.
end 

end

function scene:hide( event ) local sceneGroup = self.view local phase = event.phase

if event.phase == "will" then
    -- Called when the scene is on screen and is about to move off screen
    --
    -- INSERT code here to pause the scene
    -- e.g. stop timers, stop animation, unload sounds, etc.)
elseif phase == "did" then
    -- Called when the scene is now off screen
end 

end

function scene:destroy( event ) local sceneGroup = self.view

-- Called prior to the removal of scene's "view" (sceneGroup)
-- 
-- INSERT code here to cleanup the scene
-- e.g. remove display objects, remove touch listeners, save state, etc.

if playBtn then
    playBtn:removeSelf()    -- widgets must be manually removed
    playBtn = nil
end

end


-- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene )


return scene

1

1 Answers

2
votes

My guesses are

  1. Comment says go to level1.lua but it tries to go to levelSelect
  2. Don't use upper case in file names (in general)
  3. try removing "fade", 500 to see it it works
  4. in levelselect.lua you did not return scene or did not handle scene:create

More code and info please