Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Gideros Game Template - Page 2 — Gideros Forum

Gideros Game Template

2

Comments

  • hmm, well right no you could overwrite it.

    Like nilling or emptying or writing default values
    dataSaver.saveValue("|D|somevalue", nil)
    And writing empty tables for files
    dataSaver.save("|D|mydata", {})
    But I guess that would be one of the functionalities, I could add in time (to delete files)
  • xGuiltxGuilt Member
    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?

  • ar2rsawseenar2rsawseen Maintainer
    Hello @xGuilt ;)
    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

    +1 -1 (+1 / -0 )Share on Facebook
  • xGuiltxGuilt Member
    Oh i see, hm the game template i got here doesn't seem to have the GameManager.lua weird.

    Let me see if i got this right. In the end of a level or game, i'm supposed to run the functions:
    GameManager:setScore("IntroPack", 1)
    GameManager:getNextLevel("2ndPack", 1, True)
    to save the score for the current pack then move on to the next level or pack. Am i right?

  • ar2rsawseenar2rsawseen Maintainer
    edited May 2013
    @xGuilt it should be more like:
    --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 identification
    local 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 level
    end
    Something like that

    Likes: xGuilt

    +1 -1 (+1 / -0 )Share on Facebook
  • xGuiltxGuilt Member
    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?
  • ar2rsawseenar2rsawseen Maintainer
    For example you have pack 1 which has two levels and then pack 2 with three levels so the nextLevel method would work like
    curPack, curLevel = 1, 1
    curPack, curLevel = gm:getNextLevel(curPack, curLevel, true) --return 1, 2
    curPack, curLevel = gm:getNextLevel(curPack, curLevel, true) --return 2, 1
    curPack, curLevel = gm:getNextLevel(curPack, curLevel, true) --return 2, 2
    curPack, curLevel = gm:getNextLevel(curPack, curLevel, true) --return 2, 3
    curPack, curLevel = gm:getNextLevel(curPack, curLevel, true) --return nil, nil
    unfortunately I had no time to create an example app, but most probably I will someday, or maybe we can create something together with community

    Likes: xGuilt

    +1 -1 (+1 / -0 )Share on Facebook
  • xGuiltxGuilt Member
    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 :D
  • xGuiltxGuilt Member
    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 event
    				local 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.

  • ar2rsawseenar2rsawseen Maintainer
    @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 event
    	local 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
    	if target.cnt == 1 then
    		sceneManager:changeScene("level1", 1, conf.transition, conf.easing)
    	elseif target.cnt == 2 then
    		sceneManager:changeScene("level2", 1, conf.transition, conf.easing)
    	end --etc
    )

    Likes: xGuilt

    +1 -1 (+1 / -0 )Share on Facebook
  • xGuiltxGuilt Member
    Ahh, so i have to use conditions to check what level would play.

    "target.cnt" would be the level number or the number assigned to the box right?
    does that mean i have to make conditions like
    if curPack == 2 and target.cnt == 1 then
    sceneManager:changeScene("Pack2Level1", 1, conf.transition, conf.easing)
    end
    to check levels for other packs. Am i right? or is there a shorter way to do this?
  • ar2rsawseenar2rsawseen Maintainer
    @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:
    sceneManager:changeScene("Pack"..curPack.."Level"..target.cnt, 1, conf.transition, conf.easing)
  • xGuiltxGuilt Member
    Using tables would make it more cleaner looking, i'd go with that. Thanks :D
    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?
  • ar2rsawseenar2rsawseen Maintainer
    edited June 2013
    @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 :)

    Likes: xGuilt

    +1 -1 (+1 / -0 )Share on Facebook
  • xGuiltxGuilt Member
    ohhhh, haha i'm unfamiliar with how that works. Does that mean all those 40 levels would be stored inside one level.lua file?

    Would it go like calling a specific function in the level.lua indicating the level?
  • ar2rsawseenar2rsawseen Maintainer
    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

    Likes: xGuilt

    +1 -1 (+1 / -0 )Share on Facebook
  • xGuiltxGuilt Member
    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 :D

    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?
  • ar2rsawseenar2rsawseen Maintainer
    @xGuilt yes everything you define in Settings.lua class:
    https://github.com/ar2rsawseen/GameTemplate/blob/master/classes/Settings.lua
    is global and can be accessed from anywhere like:
    locla curPack = sets:get("curPack")
    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 size1
    elseif t.objects.type == "point" then
        --create point object at x and y coordinates with size1
    end --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

    Likes: xGuilt

    +1 -1 (+1 / -0 )Share on Facebook
  • xGuiltxGuilt Member
    oh, now i completely get the who curPack, curLevel and the sets:get/set thanks @ar2rsawseen :D

    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 :D

  • ar2rsawseenar2rsawseen Maintainer
    I haven't used it personally, but most probably yes it can work with Gideros :)

    Likes: xGuilt

    +1 -1 (+1 / -0 )Share on Facebook
  • xGuiltxGuilt Member
    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. :D

    Likes: xGuilt

    +1 -1 (+1 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    @xGuilt no usually it does not.
    Right now have no idea what could cause that
  • xGuiltxGuilt Member
    oh ok ok. Thanks for the helps :D
  • bali001bali001 Member
    edited May 2014
    I couldn't find an appropriate topic for 'View.lua' class and I didn't want to open a new one...

    Gridview:addChild function:
    function GridView:addChild(item)
      local width, height = getDimensions(item)
     
      if self.conf.animate then
        --default properties
        local animate = {}
        animate.alpha = 1
        animate.scaleX = 1
        animate.scaleY = 1
        animate.rotation = 0
        animate.y = self.startY
        animate.x = self.startX
     
        if(self.startX + width > self.width) then
          self.width = self.startX + width
        end
     
        if(self.startY + height > self.height) then
          self.height = self.startY + height
        end
     
        --copy original properties
        item.original = getProperties(item)
     
        --use spacer
        self.spacer:setPosition(self.width + width, self.height  + height)
     
        --animate
        item.tween = GTween.new(item, self.conf.duration, animate, {ease = self.conf.easing})
      else
        item:setPosition(self.startX, self.startY)
      end
      ....
    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).

    So I have to changed it (and works):
    function GridView:addChild(item)
      local width, height = getDimensions(item)
     
      -- moved outside from 'if'
      if(self.startX + width > self.width) then
        self.width = self.startX + width
      end
     
      if(self.startY + height > self.height) then
        self.height = self.startY + height
      end
     
      if self.conf.animate then
        --default properties
        local animate = {}
        animate.alpha = 1
        animate.scaleX = 1
        animate.scaleY = 1
        animate.rotation = 0
        animate.y = self.startY
        animate.x = self.startX
     
        --copy original properties
        item.original = getProperties(item)
     
        --use spacer
        self.spacer:setPosition(self.width + width, self.height  + height)
     
        --animate
        item.tween = GTween.new(item, self.conf.duration, animate, {ease = self.conf.easing})
      else
        item:setPosition(self.startX, self.startY)
      end
      ....
  • bali001bali001 Member
    edited May 2014
    in View:removeChild():
    function View:removeChild(item)
      --find and remove button
      local children = self:getNumChildren()
      for i = 1, children do
        local sprite = self:getChildAt(i)
        if(sprite == item)then
          self:__removeChild(item)
        end
      end
    end
    missing a break after self:__removeChild(item)
    children will be an invalid index (out of bounds) after removing the item
  • ar2rsawseenar2rsawseen Maintainer
    :D
    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:
    function View:removeChild(item)
      item:removeFromParent()
    end
  • bali001bali001 Member
    @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.
  • @somezombiegm yes it was just template, without any actual game. That was the whole point :)
Sign In or Register to comment.