Since you don’t have anyone near you to help, let me give you some advice.
-
Stop using scene managers like composer. - I’ve noticed you always try to make your games with a scene manager and that isn’t necessary.
-
Instead, make your game mechanic with four script files:
- config.lua
- build.settings
- main.lua
- game.lua
-
Place all of the files in the same folder (no sub-folders).
-
Define the contents of the game.lua and main.lua files as follows:
game.lua - A module containing your game code:
-- ANY REQUIRE STATEMENTS YOU NEED HERE local physics = require "physics" -- ANY LOCALS you need local gameGroup -- Start the module definition local game = {} -- == -- Game Creation Logic -- == function game.create( parent ) game.destroy() -- parent = parent or display.currentStage gameGroup = display.newGroup() parent:insert(gameGroup) -- -- YOUR GAME CREATION CODE HERE -- YOUR GAME CREATION CODE HERE -- YOUR GAME CREATION CODE HERE -- Tip: Insert all display objects into 'gameGroup' end -- == -- Game Cleanup and Destruction Logic -- == function game.destroy( ) -- YOUR GAME CLEANUP CODE HERE -- YOUR GAME CLEANUP CODE HERE -- YOUR GAME CLEANUP CODE HERE --- display.remove( gameGroup ) gameGroup = nil end return game
main.lua
io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) -- local game = require "game" game.create()
This has all the parts you need.
Later
Later, you can test how bug-free and robust your game is by changing main.lua to this:
io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) -- local game = require "game" game.create() timer.peformWithDelay( 30000, game.create ) -- destroy and re-create game in 30 seconds
If you game crashes, you know you’ve got issues and should fix them.
If not, try doing this again, but try to play the game during those 30 seconds. If it crashes you’ve got more bugs in your code. Fix them.
Much Much Much Later
_ Warning: _ If you just right to this step, you’re wasting your time… and will probably fail to make a game.
Much later, you can insert this code into a composer scene as easily as this:
play.gui - Scene file to play game
local composer = require( "composer" ) local scene = composer.newScene() local game = require "game" function scene:create( event ) local sceneGroup = self.view game.create( sceneGroup ) end function scene:destroy( event ) game.destroy() end scene:addEventListener( "create", scene ) scene:addEventListener( "destroy", scene ) return scene
main.lua - update main.lua to load composer scene
io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) -- ============================================================= local composer = require "composer" composer.gotoScene( "play" )