From what I understand you are trying to create it in main.lua. Create a new file and name if my_scene.lua (or something) and move all the code to that file. Then from main.lua use this code to open the scene:
local composer = require( "composer" ) composer.gotoScene( "my\_scene" )
main.lua should never be a scene file. It should require composer and then call composer.gotoScene(). Your scene file should be in some other file that you provide as an option to gotoScene.
main.lua:
local composer = require( "composer" ) --- rest of your main.lua composer.gotoScene( "menu" )
menu.lua:
local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) background:setFillColor( 1, 1, 1 ) sceneGroup:insert( background ) end scene:addEventListener( "create", scene ) return scene
From what I understand you are trying to create it in main.lua. Create a new file and name if my_scene.lua (or something) and move all the code to that file. Then from main.lua use this code to open the scene:
local composer = require( "composer" ) composer.gotoScene( "my\_scene" )
main.lua should never be a scene file. It should require composer and then call composer.gotoScene(). Your scene file should be in some other file that you provide as an option to gotoScene.
main.lua:
local composer = require( "composer" ) --- rest of your main.lua composer.gotoScene( "menu" )
menu.lua:
local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) background:setFillColor( 1, 1, 1 ) sceneGroup:insert( background ) end scene:addEventListener( "create", scene ) return scene