Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Dropping of frame rates — Gideros Forum

Dropping of frame rates

private_kennyprivate_kenny Member
edited December 2014 in Game & application design
Hi,

I have created a simple run and jump game that have many graphics and some interaction.
However, after some levels, the frame rate dropped from 60fps to 35++ fps on most androids phones.
It is working fine on the Gideros player.

Any idea the cause?

Comments

  • @private_kenny
    1) if it is an endless runner like thing where you create new objects constantly, then you may want to implement pool of things for reusing objects rather than creating new and destroying.

    Here's an example class with Bitmap, but you can also use it on more complex objects as box2d bodies
    http://giderosmobile.com/forum/discussion/comment/36045#Comment_36045

    2) make sure you preload all texture on scene start (you can do it easily either by using TexturePack or storing textures in the table scene property) because loading new textures, that are not yet in memory may halt game a bit, due to i/o operations

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • amin13aamin13a Member
    Accepted Answer
    My suggestions:
    1- do not use large texture
    2- reuse objects if its possible (thank you ar2rsawseen)
    3- monitor fps, lua memory, texture memory (attached)
    4- make sure removed objects are really deleted (object = nil)
    5- preload all texture on scene (thank you ar2rsawseen)
    6- do not use box2d objects if its possible (less box2d object = more fps)
    7- use movieclip class for animation

    lua
    lua
    main.lua
    940B
  • private_kennyprivate_kenny Member
    edited December 2014
    I keep these noted. Will take some time to change the structure.
    Regarding the lua memory and texture memory. What is the factor that may cause the fps to drop?
    Ah.. I forget to nil the objects.. Will keep in mind too.
  • Maybe the memory usage increase unexpected (Memory leak).
    Maybe some object is active and hidden.
    Maybe some unnecessary calculation.
    Maybe ... i don't know
    You should monitor lua memory and texture memory and fps
  • SinisterSoftSinisterSoft Maintainer
    edited December 2014
    I load all the textures at the beginning. Then I allocate them as bitmaps at each stage. Do a lot of forced garbage collection. Don't have loads of events running. Draw each set of draw call objects from the same texture map.

    Avoid box2d if you can - use it only as a last resort.

    Have loads on screen, moving, etc - no drop of frames.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • I tried loading the textures at the start and faced a simple lua programming error which I failed to resolve. Maybe someone can enlighten me?

    I have a simple background to ground bitmaps that holds the texture images. Previously, I loaded each background and ground images at each level via the loadLevel() operation.

    I've since created a function to load all the levels now to store all the images in the set as shown in createAllLevel(). Please ignore why I create 2 bitmaps for now :D

    function Background:createAllLevel()
    self.skyBitmapSet = {{} }
    self.groundBitmapSet = { {}}
    self.skyTexture = { }
    self.skyBitmaps = { }
    self.groundTexture = { }
    self.groundBitmaps = { }


    local numLevels = self.database:getMaxNumberOfLevels()
    for i=1,numLevels,1 do
    self.skyTexture[i] = Texture.new("images/levels/level_" .. i .. "/sky.png")
    self.skyBitmaps[i] = { Bitmap.new(self.skyTexture[i]), Bitmap.new(self.skyTexture[i]) }

    self.groundTexture[i] = Texture.new("images/levels/level_" .. i .. "/grass.png")
    self.groundBitmaps[i] = { Bitmap.new(self.groundTexture[i]), Bitmap.new(self.groundTexture[i]) }
    end

    self.skyBitmapSet[1] = self.skyBitmaps[1]
    self.groundBitmapSet[1] = self.groundBitmaps[1]

    end

    During the loading of the level, this is what I do:

    function Background:loadLevel(currentLevel)

    --[[
    local skyTexture = Texture.new("images/levels/level_" .. currentLevel .. "/sky.png")
    local skyBitmaps = { Bitmap.new(skyTexture), Bitmap.new(skyTexture) }

    local groundTexture = Texture.new("images/levels/level_" .. currentLevel .. "/grass.png")
    local groundBitmaps = { Bitmap.new(groundTexture), Bitmap.new(groundTexture) }

    self.skyBitmapSet[1] = skyBitmaps
    self.groundBitmapSet[1] = groundBitmaps
    ]]--

    self.skyBitmapSet[1] = self.skyBitmaps[currentLevel]
    self.groundBitmapSet[1] = self.groundBitmaps[currentLevel]

    end

    ===========================
    If I used the commented code in loadLevel where I created the bitmap and texture at each level. The self.skyBitmapSet[1] and self.groundBitmapSet[1] always have values and never nil

    However, when I use the uncommented code as shown (To load all at start). I am able to load it the first time. Subsequently, when I fire an event to call the same function loadLevel() , this time the 2 BitmapSets would be nil.

    Any idea?
  • I have the error attempt to perform arithmetic on local 'index' (a string value) when accessing the BitmapSets. It means nil right?
  • string is not nil.
    what do you pass as currentLevel? maybe it's not a number.
  • loadLevel was called at the beginning and each time I fired a change level event. If it was called at the beginning, loadLevel(1) will invoke level1 set of bitmaps and loadLevel(2) will invoke level2 set of bitmaps. However when shifting to next level (ie.) call loadLevel(n), where n is the level, it would indicate an error.
  • you should print out the bitmapsets to see if they are nil or what else.

    the code seems ok for me so either you don't generate those levels (i.e. self.database:getMaxNumberOfLevels() is 1 or something small) or when you call loadLevel(currentLevel), currentLevel is not the value you think.

    in any case debugging should clarify a lot (either print out things along the code or use http://studio.zerobrane.com/ for better debugging (watch expressions, pause code at a line, etc)
  • When I created the bitmaps at the start:
    The following Bitmap index at:
    createAllLevel:
    Index 1 at createAllLevel = 1
    Index 1 at createAllLevel = 2
    Index 2 at createAllLevel = 1
    Index 2 at createAllLevel = 2
    LoadLevel(2)
    Index 2 at loadlevel = 1
    Index 2 at loadlevel = 2

    But when loading from level 1 to level 2 after firing event:
    LoadLevel(2)
    Index 2 at loadlevel = __userdata
    Index 2 at loadlevel = __parent
  • i'm not sure but you know that as you use it, Background is a class, so i assume you have the line
    Background=Core.class(Sprite) at the beginning or something like that
    and then you should make and work with an instance of this class, namely you make
    myBackground=Background.new()
    and then you work with this instance, e.g.
    myBackground:createAllLevel()
    and e.g.
    myBackground:loadLevel(2)

    and so NOT Background:loadLevel(2) and NEITHER Background.loadLevel(2) and NEITHER myBackground.loadLevel(2) (notice that here there is a '.' instead of ':', that's not good for calling a class function)
  • Yes. Background is a class

    I am also using : and not .

    I shall put this aside first. Compressing the images does the trick for now. This had been holding me for a while. Thanks keszegh!
  • well, sorry for not being able to help finding the error.
    hope you will have some luck with it later. you can send the whole lua file in pm or something and if i spot something, i will let you know.
Sign In or Register to comment.