I noticed that some of my code was getting a little long. So I have been creating additional .lua files such as 'game over.lua'
That have a function in them like
function endGame(scene) -- Game over
local self = {}
self.scene = scene;
local function reduceChangeSceneCountDown()
self.secondsUntilChange = self.secondsUntilChange +1;
if(self.secondsUntilChange == 5) then
self.timer:stop(); -- stop timer counting down
-- decide which scene to show
sceneManager:changeScene("Game Over", .5, SceneManager.crossfade, easing.outBack);
end
end
if(self.scene.secondsLeft == 0) then
self.secondsUntilChange = 0;
local changeSceneCountDown = Timer.new(1000,5);
changeSceneCountDown:addEventListener(Event.TIMER, reduceChangeSceneCountDown);
changeSceneCountDown:start();
self.timer = changeSceneCountDown;
end
end |
Then using this in my level one code (which was getting too long)
This helps with organization, but is it 'allowed'?
Thanks
Comments
What do you think?
I generally have a separate class (and therefore file) for each of:
1) the game itself. This is generally a singleton or global that I can reference from anywhere else.
2) each scene
3) each significant game object that has its own behaviour.
Best regards
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
You sir are a lifesaver! :-)))