I’m a complete newbie, so please I’m sorry if I’m being too stupid …
I’m creating a small flappy bird clone (wow, how original…) just to learn how to use the engine, but after building it and running on a Moto G2, I see the game is running super slowly.
It’s ok on Desktop, but I can’t figure out what’s wrong.
Thank you in advance, and again, sorry if it’s a stupid question.
Are you doing any animation yourself in the scripts update function? In that case make sure to use the delta time, dt, argument instead of a fixed step.
So instead of:
function update(self, dt)
self.anim_value = self.anim_value + 1.0
...
end
you would use dt instead:
function update(self, dt)
self.anim_value = self.anim_value + dt
...
end
If you feel that the performance is the problem on the other hand, keep the calculations to a minimum inside the update functions since these are run each frame. Maybe try to rely on the built in gameobject/GUI animation system instead in cases where possible.
There are several things that may cause this. See Sven’s post for some tips. Another thing to watch out for is too many messages sent each frame. Mobile devices can easily choke on that. Some print() statements in the code can help see if that’s the problem.
Also, many layers of graphics can bee too much for the mobile’s graphics card to handle too.
Hope you find the issue, otherwise just drop another line and we’ll help you do some profiling.
You’ve already received some nice tips from Sven and Mikael, but if you’re still not able to figure it out you might try:
Use the visual or html profiler to figure out where the bottleneck is (scroll down on this page: http://www.defold.com/doc/debugging). Are you constantly above the frame budget? Is it the number of draw calls? Is it a script that takes too long?
Have you modified the render script or any of the shaders?
If you’re having problems with many draw calls you should consider reducing the number of atlases (combine them). If you have a lot of gui scenes you should consider using layers to optimise draw calls (see gui documentation).
Have you tried the game on another mobile device? If so, is it equally slow or does the game run at the expected speed? If there’s a noticeable difference it could be an issue with the GPU and shaders if you have customised them.
Nothing in your setup sticks out what I can see. Can you try to run the web profiler (see Björn’s post above for a link to how) and post a screenshot on what it captures?
And no worries, folders are a good idea. It’s one of the goals with the editor that you should be able to organize and easily re-organize your files as you wish.
Can’t see anything that should be bad for performance in that code. But one thing I just realised you could try, if the game is “slow”, is that you might want to try to enable variable_dt in game.project.
After enabling the variable_dt in game.project I noticed the game runs a little bit faster when I scale the screen up. It’s like if I had to make my calculations based on the screen resolution, I don’t know.
In general you seem to have quite a good frame time anyway (<4ms at the selected frame), the spikes of 18ms is still almost 55 FPS. I don’t see any performance problem really, could it just be that some of your animations don’t depend on the frame delta?
As I said, when the window size is bigger, the game gets really slow. It’s worth mentioning that when it comes to Moto G the screen is smaller but the dpi is still high: 720 x 1280 pixels (~294 ppi).
The VSync.wait in this snapshot means that the video card essentially is waiting for the previous frame to finish to avoid screen tearing, so not really a performance issue. As I said in my previous reply, I would suspect the game “feels slow” due to some inconsistencies with not using delta time when updating the animations. Are you updating animations/positions/rotations anywhere else?
The video recorder slows down the game a little, but you still can notice at 0:31 seconds when I change the resolution, the game starts slowing down a lot.
I really want to use this engine… I don’t know if I’m doing something wrong in the project configuration. I’d appreciate if any of you who already made any android game using Defold could make a simple tutorial on how to setup a project for android, with configurations and optimizations, because I think I have done something wrong, but I can’t figure out what.