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
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- 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
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 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
Avoid box2d if you can - use it only as a last resort.
Have loads on screen, moving, etc - no drop of frames.
https://deluxepixel.com
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
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?
what do you pass as currentLevel? maybe it's not a number.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
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)
Fragmenter - animated loop machine and IKONOMIKON - the memory game
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
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)
Fragmenter - animated loop machine and IKONOMIKON - the memory game
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!
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.
Fragmenter - animated loop machine and IKONOMIKON - the memory game