Hi
I want to do a pinball game that have many levels and for each level I will have a different game settings
I want to make this game using the Compressor lib and I want to split my code on few files
Mydaya.lua file that will hold the game and levels settings
myFunc.lua file that will hold my game functions
levelN.lua files, a file for each level, in each file I will place my scene object, call my functions and listeners
In the game I have a button that on each touch event change the paddle rotation
I need help to understand how to call a function from the touch event.
This code works when I have it on the same file, I don’t know how and what to transfer with the function call (btnLeft:addEventListener(‘touch’, myFunc.movePaddle))
****************
**Level1.lua
****************
function gameListeners(action)
if(action == ‘add’) then
btnLeft:addEventListener(‘touch’, myFunc.movePaddle)
else
btnLeft:removeEventListener(‘touch’, myFunc.movePaddle)
end
end
– “scene:create()”
function scene:create( event )
local sceneGroup = self.view
– add paddle to the scene
paddleLeft = display.newImage(‘paddleLeft.png’)
paddleLeft.name = ‘padLeft’
paddleLeft.x = _W
paddleLeft.y = _H
paddleLeft.rotation = 45
paddleLeft.anchorX = 0.5
paddleLeft.anchorY = 0.8
physics.addBody(paddleLeft, ‘static’, {shape = paddleLshape})
sceneGroup:insert (paddleLeft);
–add buttons to the scene
btnBlue = display.newImage(‘btnBlue.png’)
btnBlue.x= _HW/2; btnBlue.y = _HH*25.5/16; --btnBlue.alpha = 0.35
btnBlue.name = ‘btnblue’
sceneGroup:insert (btnBlue);
end
– “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
gameListeners (‘add’)
end
end
************
**myFunc.lua
************
local myFunc = {}
function movePaddle(e)
if(e.phase == ‘began’ and e.target.name == ‘btnleft’ and paddleMove ~= true) then
paddleleft.rotation = paddleleft.rotation*-1
elseif(e.phase == ‘began’ and e.target.name == ‘btnRight’ and paddleMove ~= true) then
paddleRight.rotation = paddleRight.rotation*-1
end
end
func.movePaddle = movePaddle
return myFunc
Thank you
Guy