hi sirs,
With the help of sirs here, i was able to complete my second game. now the thing is in my phone and other phone tested, it shows drop in fps and i noticed somewhat the phone heats, but my game is just a simple jumper, obstacles come, you just dodge by jumping over it, that's all. It's very simple in mechanics and i really suspect that my programming to blame -causing memory leaks etc.
As a newbie, I need to know sirs what is your golden-rule-to-effecient-coding or at least what you keep in mind when making your games.
I noticed myself: (i need to know sirs if these causes it)
-i usually use a lot of enter frame events..
-i like to put mathematical operations as arguments to functions like..
avatar:run(movSpeed*movAdd*t) |
-i use just change the texture when using animations.. and using enter frame to control it..
that is one enter frame event per animation in one object.
thanks.
Comments
Here's what I find... When I'm working on a game, I forget to test memory leaks and FPS - the main things that need to work for my game to run smoothly. So, every now and then during development, it's a good idea to run the FPS and memory leak checks.
It's highly likely that you will have memory leaks and FPS problems and there's always something causing them.
Incidentally here's the code for memory leak checks
That's a bit of a vague answer but each game is different. The code you mentioned doesn't seem problematic and Gideros is a very FAST framework. It only usually slows down if there's a problem with one of your classes.
In my experience, the main cause for memory leaks is not removing something from the stage properly OR having a table reference to a sprite that prevents it from being garbage collected.
One last thing, you didn't mention what your testing device was. It could be that it's an older model that is safe to disregard (but it might not be!) Or it could be a problematic class, too many sprites (unlikely on modern devices...) or something different. Code in a way to turn parts of your game off and then go from there. You'll soon find it.
Likes: jdbc, neverjoy
The main problem that slow down your game usually is that, or any renderTarget/shader object. Don't worry about calculation to much.
[Also of course, memory leak like Tom2012 explained]
Likes: neverjoy
Use Movieclip class to change texture for animation. Its very fast. One of my game runs in 60 fps on low end device with 100 sprites ( 14 textures 60*60 size for each of them. ) and a lot of calculation in lua.
Another point: Never use large textures. Never!
Likes: neverjoy
I like it very much.
Person = gideros.class(Sprite)
function Person:init()
--members
self.myName = "Amin"
self:addEventListener(Event.ADDED_TO_STAGE, self.onAddedToStage, self)
self:addEventListener(Event.REMOVED_FROM_STAGE, self.onRemovedFromStage, self)
end
function Person:onAddedToStage()
self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end
function Person:onRemovedFromStage()
self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end
function Person:onEnterFrame()
-- every frame this code is run.
end
function Person:myMethod()
return self.myName
end
Now somewhere in the code:
local me = Person.new()
local name = me:myMethod()
Likes: neverjoy, MoKaLux
1) RAM use. All images are decompressed at power of 2. So a 513 X 513 image will take the space of a 1024x1024 image. So in RAM terms that would be 1024x1024 pixels X 32 bits divided by 8 bits per byte =4MB, whatever it's compressed PNG size. So think about how many images you are loading and are they really necessary? It's best to keep in mind power of 2s to be efficient. Don't go slightly over a power of 2 threshold unless you really need to. Using too much RAM is a big performance killer.
2) Draw calls. I remember a few years back reading that most mobiles couldn't draw more than 3 layers at 60FPS. It might have improved a bit since then, but we try our best to stick to no more than 3 or 4 max. Don't layer sprites over other sprites where you don't need to. You say your game is a runner - have you got large backgrounds covered by large foregrounds etc? If so, think about your design a bit to reduce overdraw.
3) Overuse of transparencies. Some transparency is essential in games, but it's also very GPU intensive. It still counts as a draw call, and is actually worse than an opaque image. A border created as a one sprite window, for example, is terrible for the GPU - It is much better to create the horizontal and vertical parts as 4 separate sprites.
Generally the main drags on performance are to do with what, how and how much you are rendering, rather than maths logic and, as mentioned above, whether you are clearing your memory.
Likes: neverjoy, MoKaLux
Even if I am using scenemanager, when I change page to empty one, collectgarbage("count") doesnt decrease.
Is it normal?
If not ,What can be the reason?
I think, It should be something like 10-20.