Just a question, i've set my first pack to only have 1 level (Supposed to be an introduction only with some cut scene) and after that, the player could proceed to the next pack but after finishing the first pack with only 1 level, the second pack doesn't unlock. How can i set when a pack unlocks or a certain pack unlocking after a certain level is finished. Like the third pack after clearing level 6 of the 2nd pack even if that pack has 10 or more levels?
Usually you would create an instance of GameManager providing current pack and level, and call :unlockLevel(pack, level) There is also a method :getNextLevel(pack, level, unlock) which gives you pack and level of next level and bool to unlock it or not, so you could jump to next level immediately.
--first you load your packs info somewhere in main lua probably--load packs and level amounts from packs.json
packs = dataSaver.load("packs")
then in your level scene:
--then I usually store current pack and level somewhere I can access it globally--either global variables or global settings class
curPack =1
curLevel =1--create instance of game manager providing pack info and player identificationlocal gm = GameManager.new(packs, playerid)--then on the level complete save score
gm:getScore(curPack, curLevel)--and get next pack and level and unlock it--it will switch to next pack if this was the last level in the pack automatically
curPack, curLevel = gm:getNextLevel(curPack, curLevel, true)if curPack then--if current pack is not nil it means there are more levels to play--then you can change the scene to next level--and curPack and curLevel would store the information of next pack and levelend
ah, i see. So in every level i will store the current pack and level in a variable like what you did with the curPack and curLevel what i don't quite get is the
"curPack, curLevel = gm:getNextLevel(curPack, curLevel, true) it would be like 1,1 = gm:getNextLevel(1,1,true) given that the current pack and level is 1. Or does the getNextLevel function moves from the current pack and level and not chosen specifically?
by the way, would you happen to have a simple sample for the application of this?
ok, i've read the function in the gamemanager.lua. So it actually gets the current pack and level and adds 1 to the current level and if there aren't any more levels for that pack then it adds 1 to the pack and level goes back to 1.
It became much much more simple now. Thank you so much
Hi, it's been a long time, been busy with school -,-, I was wondering about this block of code in the level_select.lua
--add event listener
box:addEventListener("click", function(e)--get target of eventlocal target = e:getTarget()--save selected level
sets:set("curLevel", target.cnt)--set to show description
sets:set("showDescription", true)--stop propagation
e:stopPropagation()--go to selected level
sceneManager:changeScene("level", 1, conf.transition, conf.easing)
This code is for giving the unlocked boxes a function that when they're clicked, they go to the level but at the end of the line it only changes it's scene to "level.lua" Does that mean i have to create all the levels in only one lua? Since what i've done is create different lua for levels and misc level related stuff like cutscenes.
@xGuilt yes the idea was that in the level.lua you determine what to load based on the level and pack number, but you can also determine it here as in :
--add event listener
box:addEventListener("click", function(e)--get target of eventlocal target = e:getTarget()--save selected level
sets:set("curLevel", target.cnt)--set to show description
sets:set("showDescription", true)--stop propagation
e:stopPropagation()--go to selected levelif target.cnt ==1then
sceneManager:changeScene("level1", 1, conf.transition, conf.easing)elseif target.cnt ==2then
sceneManager:changeScene("level2", 1, conf.transition, conf.easing)end--etc)
@xGuilt you are right, but there is a shorter way like creating table of levels:
local t {}
t[1]={}
t[1][1]="Pack1Level1"
t[1][2]="Pack1Level2"--and then using it like
sceneManager:changeScene(t[curPack][target.cnt], 1, conf.transition, conf.easing)
or if you have a standard naming convention like "Pack1Level1" etc, you can also do simply:
Using tables would make it more cleaner looking, i'd go with that. Thanks Hm so if i have 4 packs having 10 levels each then that means i'm going to have 40 conditions to get all the levels right?
@xGuilt yes, which also means you will have 4x10 lua files, thats why I thought of using single level.lua to handle that all and store only some json configurations to handle loading different levels which would be loaded dynamically based on curPack and curLevel
well what we have for example in Mashballs is that there are level definitions, stored in level folder like level1-1.json, level1-2.json etc level.lua then based on curPack and curLevel loads the level definition, interprets it and displays the level to user.
That way it is flexible enough and we can actually have a level editor outside of Gideros, which exports this json level definitions files
ah. So the pack_select and the level_select will actually pass on the curPack and the target.cnt to the level.lua which loads the json file. Now it sounds much more simplier
but i have no idea how to use json to define levels. I know svg level definition but i know it works differently since it's based of from an image. Do you have a small sample of how it works?
But about levels, well it's completely based on your game specific, for example in Mashballs http://jenots.com/mashballs difference between levels is basically what objects appear and where they appear.
We have a custom level editor to set those things, but in simplified version it looks like this: {"objects":[{"type":"touch","x":250,"y":400,"rotation":0,"size1":30,"size2":0},{"type":"touch","x":525,"y":400,"rotation":0,"size1":30,"size2":0},{"type":"point","x":250,"y":300,"rotation":0,"size1":20,"size2":0},{"type":"point","x":525,"y":300,"rotation":0,"size1":20,"size2":0}]}
Then inside level.lua we read the level definition into lua table, iterate through objects and look,
if t.objects.type=="touch"then--create touch object at x and y coordinates with size1elseif t.objects.type=="point"then--create point object at x and y coordinates with size1end--etc
We use dataSaver http://giderosmobile.com/tools/datasaver which allows easily to save and load lua tables and I think it should even be included with the Game Template
oh, now i completely get the who curPack, curLevel and the sets:get/set thanks @ar2rsawseen
i've searched on google about json level editors and tiled came up. Apparently it can save tilemaps in json. I haven't tried it out yet, but i've seen some posts here in the forum that tiled can be used along with gideros right?
it's a bit out of our topic but does the ace slider that comes with the game template in it's pack_select.lua normally has a 3~5 second delay before the creates or back button gets their functions? because after moving from another scene to the pack select, it takes a few seconds before they work, even clicking them won't do anything.
But when self.conf.animate is false, width and height of the gridview are not updated at all, getWidth() and getHeight() returns 0 (at least in my case).
function View:removeChild(item)--find and remove buttonlocal children = self:getNumChildren()for i =1, children dolocal sprite = self:getChildAt(i)if(sprite == item)then
self:__removeChild(item)endendend
missing a break after self:__removeChild(item) children will be an invalid index (out of bounds) after removing the item
@ar2rsawseen: thx And there is no problem with that code at all, it's working! I need a scrollable view in my game which displays images in a grid on slides, so I "merged" AceSlide and GridView into "one" (with dynamic slide load) from your Game Template.
By the way, expected some kind of views in next version of Gideros?
@ar2rsawseen Hey, I started making my game by modifying your template. I've download it again to check how some things were originally, but there's no gameplay. Right after selecting the first level of the first pack, a blank screen appears without anything else.
Comments
Like nilling or emptying or writing default values
If you check the GameTemplate repository: https://github.com/ar2rsawseen/GameTemplate
You'll see there is a class GameManager, which is just a simple example of how you could manage your games, unlock levels, save scores etc.
https://github.com/ar2rsawseen/GameTemplate/blob/master/classes/GameManager.lua
Usually you would create an instance of GameManager providing current pack and level, and call :unlockLevel(pack, level)
There is also a method :getNextLevel(pack, level, unlock) which gives you pack and level of next level and bool to unlock it or not, so you could jump to next level immediately.
Likes: xGuilt
Let me see if i got this right. In the end of a level or game, i'm supposed to run the functions:
Likes: xGuilt
"curPack, curLevel = gm:getNextLevel(curPack, curLevel, true)
it would be like 1,1 = gm:getNextLevel(1,1,true) given that the current pack and level is 1. Or does the getNextLevel function moves from the current pack and level and not chosen specifically?
by the way, would you happen to have a simple sample for the application of this?
Likes: xGuilt
It became much much more simple now. Thank you so much
Likes: xGuilt
"target.cnt" would be the level number or the number assigned to the box right?
does that mean i have to make conditions like
like creating table of levels:
Hm so if i have 4 packs having 10 levels each then that means i'm going to have 40 conditions to get all the levels right?
Likes: xGuilt
Would it go like calling a specific function in the level.lua indicating the level?
is that there are level definitions, stored in level folder
like level1-1.json, level1-2.json etc
level.lua then based on curPack and curLevel loads the level definition, interprets it and displays the level to user.
That way it is flexible enough and we can actually have a level editor outside of Gideros, which exports this json level definitions files
Likes: xGuilt
but i have no idea how to use json to define levels. I know svg level definition but i know it works differently since it's based of from an image. Do you have a small sample of how it works?
https://github.com/ar2rsawseen/GameTemplate/blob/master/classes/Settings.lua
is global and can be accessed from anywhere like:
for example in Mashballs
http://jenots.com/mashballs
difference between levels is basically what objects appear and where they appear.
We have a custom level editor to set those things, but in simplified version it looks like this:
{"objects":[{"type":"touch","x":250,"y":400,"rotation":0,"size1":30,"size2":0},{"type":"touch","x":525,"y":400,"rotation":0,"size1":30,"size2":0},{"type":"point","x":250,"y":300,"rotation":0,"size1":20,"size2":0},{"type":"point","x":525,"y":300,"rotation":0,"size1":20,"size2":0}]}
Then inside level.lua we read the level definition into lua table, iterate through objects and look,
http://giderosmobile.com/tools/datasaver
which allows easily to save and load lua tables and I think it should even be included with the Game Template
Likes: xGuilt
i've searched on google about json level editors and tiled came up. Apparently it can save tilemaps in json. I haven't tried it out yet, but i've seen some posts here in the forum that tiled can be used along with gideros right?
oh and again, thanks for the help
Likes: xGuilt
Likes: xGuilt
Right now have no idea what could cause that
Gridview:addChild function:
So I have to changed it (and works):
thank you
children will be an invalid index (out of bounds) after removing the item
Oh my god, did I wrote that? The things you see at your code after 2 years of writing
It could have been handled much more elegantly:
I need a scrollable view in my game which displays images in a grid on slides, so I "merged" AceSlide and GridView into "one" (with dynamic slide load) from your Game Template.
By the way, expected some kind of views in next version of Gideros?