Hi guys,
I need some help in solving this problem.
I have a LUA file called gameUI which is used to handle the user interface for my game (creating touch area for character control, creating pause buttons etc). The problem is, I couldn’t figure out how to trigger a method inside my primary game scene. For this case I’m trying to call the pauseGame() method inside stageOne.lua from gameUI.lua.
----------------------- -- gameUI.lua ----------------------- local bui = {} local NewBattleUI local Group function NewBattleUI(Props) -- codes for creating touch control, pause button -- etc etc -- ### Touch Event Handler ### Group.onDrag = function ( event ) local phase = event.phase if "began" == phase or "moved" == phase then if (event.target.myName == "touch") then targetX = event.x targetY = event.y elseif (event.target.myName == "pauseButton") then -- code to trigger pause button inside stageOne.lua end end return true end Group.bigSquare:addEventListener( "touch", Group.onDrag ) Group.pauseButton:addEventListener( "touch", Group.onDrag ) return Group end bui.NewBattleUI = NewBattleUI return bui ----------------------- -- stageOne.lua ----------------------- function pauseGame() -- this is the method I'm trying to trigger -- pause timers, event handlers etc end function scene:create(event) -- codes end function scene:show( event ) -- codes end function scene:hide( event ) -- codes end function scene:destroy( event ) -- codes end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene
I’m not exactly sure if I’m doing this the right way. My thinking was to use a single LUA file to handle all my game controls so that I can easily re-use them when I create new stages.
I tried experimenting by doing something like 'local stage1 = require(“stageOne”) but those ended up in error.
Any ideas?
