Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Improve use of composer for different game modes
Started by maximo97 Feb 07 2018 12:43 AM

6 replies to this topic
game modes composer
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

maximo97

[GLOBAL: userInfoPane.html]
maximo97
  • Contributor

  • 244 posts
  • Corona SDK

Hello everyone!

 

In my game I have different game modes.

Every game mode is a different lua file with composer scena.

 

The files have the following structure:

--modules that I use for all modes
local allModule_1      = require("allModule_1")
local allModule_2      = require("allModule_2")
local allModule_3      = require("allModule_3")

--modules that I use only for this mode
local thisModModule_1 = require("thisModModule_1")
local thisModModule_2 = require("thisModModule_2")
local thisModModule_3 = require("thisModModule_3")

--variables that I use for all modes
local allVar_1
local allVar_2
local allVar_3

--variables that I use only for this mode
local thisModVar_1
local thisModVar_2
local thisModVar_3


--functions with the same code for all the mods that use the same variables (es. thisModVar_1) for all the mods. 
--However, these variables (es. thisModVar_1) can be modified by personal methones of a mod (es. "enterFrame")
local function gameOver()
end
local function pause()
end
local function resume()
endimprove use of composer for different game modes

--Different functions that change according to the modality and modify both variables (es. allVar_1 and  thisModVar_1)
local function enterFrame(event)
end
local function other1( group )
end
local function other2()
end

--Naturalmete created different things according to the modality
function scene:create( event )
end

function scene:show( event )
end

function scene:hide( event )
end

function scene:destroy( event )
end

Therefore in essence for each mode I copy some identical functions and some equal variables. The problem of course and that if I have to make a change I have to do it all.

Is there a way to optimize this?



[TOPIC: post.html]
#2

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,219 posts
  • Corona SDK

Instead of having level1.lua, level2.lua try and change it to only have level.lua and then have your level data stored in JSON files called level1.json, level2.json.

 

Then for each level you simply load the relevant JSON file to configure your level.



[TOPIC: post.html]
#3

maximo97

[GLOBAL: userInfoPane.html]
maximo97
  • Contributor

  • 244 posts
  • Corona SDK

Thanks two help in one day!

 

However what you said I do already. I'll give you an example.

 

Mode 1 make goals (I'll load the levels apart level1.lua , level2.lua...)

Mode 2 make basket(I'll load the levels apart level1.lua , level2.lua...)

Mode 3 ..

 

The fact is that for example the gameOver function in all the scenes collects the score and then shows it on video.

The same code for all modes....

I explained myself better?



[TOPIC: post.html]
#4

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,219 posts
  • Corona SDK

Still not entirely sure what you mean....  But if you are having a gameOver() function in each module then I would put all those in a common module and then require that in your other modules.

 

Then when the player is dead (or whatever) simply call common.gameOver().  This function should create a group to display your game over UI.  Because this function is not tied to a single lua file it will display on top of whatever scene it is called from.



[TOPIC: post.html]
#5

maximo97

[GLOBAL: userInfoPane.html]
maximo97
  • Contributor

  • 244 posts
  • Corona SDK

I apologize if I do not explain how I should. Probably because I'm not a native speaker..

 

However, it seems to me that we are almost there. Your solution is fine and that's what I do in other parts of the game.

But in this case to gameOver I should pass the variables that I have defined ("variables that I use for all modes").

 

So I wondered if there was a way to make a composer scene almost like a class.

So I can have some variable and functions that are the same for all mode and then, according to the mode, I can change/add only what I need.



[TOPIC: post.html]
#6

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,219 posts
  • Corona SDK

Yeah I would pass what you need to the function, so do something like common.gameOver(score).

 

If you mean can you have a base scene and then inherit from that scene and add extra functionality then that is not possible (AFAIK).



[TOPIC: post.html]
#7

maximo97

[GLOBAL: userInfoPane.html]
maximo97
  • Contributor

  • 244 posts
  • Corona SDK

Well then I'll do it, I hoped there are other ways.

 

Thanks again for your time!!




[topic_controls]
[/topic_controls]