# \[ Android \] Game running extremely slow

**URL:** <https://forum.defold.com/t/android-game-running-extremely-slow/285>\
**Category:** Questions\
**Created:** [October 3, 2015, 6:14am UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285 "2015-10-03T06:14:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mobster\_squirrel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mobster_squirrel/32/95_2.png) [@mobster\_squirrel](https://forum.defold.com/u/mobster_squirrel)\
**Post date:** [October 3, 2015, 6:14am UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/1 "2015-10-03T06:14:54Z")

</div>

**Hello Defold community!**

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.

---

<div class="post-metadata">

**Author:** ![sven](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sven/32/1086_2.png) [@sven](https://forum.defold.com/u/sven)\
**Post date:** [October 3, 2015, 6:52am UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/2 "2015-10-03T06:52:47Z")

</div>

Awesome of you to give the engine a try!

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.

Let us know how it goes! 😄

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 3, 2015, 7:01am UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/3 "2015-10-03T07:01:13Z")

</div>

Welcome to Defold!

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.

Cheers,

Mikael

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 3, 2015, 7:53am UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/4 "2015-10-03T07:53:30Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![mobster\_squirrel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mobster_squirrel/32/95_2.png) [@mobster\_squirrel](https://forum.defold.com/u/mobster_squirrel)\
**Post date:** [October 3, 2015, 3:11pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/5 "2015-10-03T15:11:42Z")

</div>

First, Thank you all, I’m really amazed on how responsive and cheerful you guys are 😱.

Now, this is the code I’m running:

```
local gravity = -0.03
local tapped = false

local max_bird_angle_left = vmath.quat_rotation_z((math.pi) / 4)	
local max_bird_angle_right = vmath.quat_rotation_z(-math.pi / 2) 

function init(self)

    msg.post(".", "acquire_input_focus")

    self.velocity = vmath.vector3(0, 0, 0)

    self.angle = vmath.quat()
    self.rotation_angle = vmath.quat()
    self.bird_direction = vmath.quat()

    self.rotation_speed = 0.001

end

function update(self, dt)

    local pos = go.get_position()

    pos = pos + self.velocity

    self.velocity.y = self.velocity.y + gravity * dt

    self.rotation_angle = vmath.slerp(self.rotation_speed, self.rotation_angle, max_bird_angle_right)

    go.set_position(pos)
    go.set_rotation(self.rotation_angle)

end

function on_message(self, message_id, message, sender)
    if(message_id == hash("tap") and tapped == false) then	
	self.velocity.y = 0.24
	self.rotation_angle = vmath.quat_rotation_z(45 * math.pi / 180)
	tapped = true
    else 
	if(self.velocity.y < -0.02) then 
   	 	self.velocity.y = -0.02; 
   	 	tapped = false
   	end
    end
end

function on_input(self, action_id, action)

    if action_id == hash("tap") then
	msg.post('#', 'tap')
    end
end

```

( Sorry for the hacky tap thing, I still don’t know how to handle taps! )

I followed the **car game tutorial** but also wanted to make something different.

* * *

The project is organized in folders. **Is that bad?**

- main
  - audio
    - sfx
    - bgm

  - collections
    - bird.collection
    - background.collection

  - scripts
    - bird.script

  - sprites
    - game\_sprites.atlas

My project settings at the moment are:

 ![](https://forum-defold-uploads.b-cdn.net/original/1X/f0f074ee5603cef0828c268c1943bcc0cbebf478.JPG)

**graphics**

default\_texture\_min\_filter: **linear**  
default\_texture\_mag\_filter: **nearest**

max\_debug\_vertices: **10000**  
texture\_profiles: **/builtins/graphics/default.texture\_profiles**

* * *

On the desktop I notice that when I scale up the window, to something like **800x600** the game starts getting slow.

Do you have any clue on what’s going on?

TIA!

~ mobs

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 3, 2015, 3:45pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/6 "2015-10-03T15:45:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sven](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sven/32/1086_2.png) [@sven](https://forum.defold.com/u/sven)\
**Post date:** [October 3, 2015, 4:00pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/7 "2015-10-03T16:00:19Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![mobster\_squirrel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mobster_squirrel/32/95_2.png) [@mobster\_squirrel](https://forum.defold.com/u/mobster_squirrel)\
**Post date:** [October 3, 2015, 4:12pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/8 "2015-10-03T16:12:15Z")

</div>

Ok, here’s what I got from the profiler:

 ![](https://forum-defold-uploads.b-cdn.net/original/1X/ea8380587a0a6839f43038068661a10f30df527f.JPG)

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.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 3, 2015, 4:22pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/9 "2015-10-03T16:22:53Z")

</div>

Thanks! The web based profiler gives better information but from what your screen it might be too much graphics to render.

Do you have lots of background graphics? Big textures in many layers?

Would you mind trying the web profiler as well?

---

<div class="post-metadata">

**Author:** ![mobster\_squirrel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mobster_squirrel/32/95_2.png) [@mobster\_squirrel](https://forum.defold.com/u/mobster_squirrel)\
**Post date:** [October 3, 2015, 4:35pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/10 "2015-10-03T16:35:36Z")

</div>

> [@sicher](#):
>
> Do you have lots of background graphics? Big textures in many layers?

Well, I have 2 sprites in the **background.collection** (for the background of course), each of them 144x256 .png images.

For the bird, I have 3 small 17x16 (pretty irregular) PNG sprites.  
One animation ( with these 3 frames) in the game\_sprite.atlas.

> [@sicher](#):
>
> Would you mind trying the web profiler as well?

No at all!

 ![](https://forum-defold-uploads.b-cdn.net/original/1X/191eebda57dbc0d505dd149489dc85b720be0e59.JPG)

( Beginners can’t post multiple images, so I’m dividing it in multiple posts )

---

<div class="post-metadata">

**Author:** ![mobster\_squirrel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mobster_squirrel/32/95_2.png) [@mobster\_squirrel](https://forum.defold.com/u/mobster_squirrel)\
**Post date:** [October 3, 2015, 4:36pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/11 "2015-10-03T16:36:38Z")

</div>

![](https://forum-defold-uploads.b-cdn.net/original/1X/6a0f88f2ab2ede87d8208e2348126c6b8d96b7b5.JPG)

---

<div class="post-metadata">

**Author:** ![mobster\_squirrel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mobster_squirrel/32/95_2.png) [@mobster\_squirrel](https://forum.defold.com/u/mobster_squirrel)\
**Post date:** [October 3, 2015, 4:37pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/12 "2015-10-03T16:37:27Z")

</div>

![](https://forum-defold-uploads.b-cdn.net/original/1X/f62001f96a41d0dbf688017ae736d3916c2f456d.JPG)

---

<div class="post-metadata">

**Author:** ![mobster\_squirrel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mobster_squirrel/32/95_2.png) [@mobster\_squirrel](https://forum.defold.com/u/mobster_squirrel)\
**Post date:** [October 3, 2015, 4:37pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/13 "2015-10-03T16:37:59Z")

</div>

![](https://forum-defold-uploads.b-cdn.net/original/1X/796d03cfb853e481ddd6c7da71aad0bad072c265.JPG)

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [October 3, 2015, 4:45pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/14 "2015-10-03T16:45:00Z")

</div>

Thanks a lot! If you click one of those large red frames at the top, you will get details on what happens there.

The red ones are frames where the game stalls. If you get a lot of those you may see a slowdown, or experience hitches.

It seems like your graphics is okay, but just to be safe. Try to remove all backgrounds and see if the game speeds up.

---

<div class="post-metadata">

**Author:** ![sven](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sven/32/1086_2.png) [@sven](https://forum.defold.com/u/sven)\
**Post date:** [October 3, 2015, 4:50pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/15 "2015-10-03T16:50:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mobster\_squirrel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mobster_squirrel/32/95_2.png) [@mobster\_squirrel](https://forum.defold.com/u/mobster_squirrel)\
**Post date:** [October 3, 2015, 4:50pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/16 "2015-10-03T16:50:44Z")

</div>

I rebuilt the project and clicked in the red bar, this is what I got:

 ![](https://forum-defold-uploads.b-cdn.net/original/1X/b45aea5b8e8562f76e116a79aba849cc6baeb933.png)

---

<div class="post-metadata">

**Author:** ![mobster\_squirrel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mobster_squirrel/32/95_2.png) [@mobster\_squirrel](https://forum.defold.com/u/mobster_squirrel)\
**Post date:** [October 3, 2015, 4:57pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/17 "2015-10-03T16:57:53Z")

</div>

After maximizing the window and running the profiler I got this:

 ![](https://forum-defold-uploads.b-cdn.net/original/1X/81aaa2d7c24f1cdd8e8b9019a6c203b43ed028fe.png)

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).**

It’s weird…

---

<div class="post-metadata">

**Author:** ![sven](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sven/32/1086_2.png) [@sven](https://forum.defold.com/u/sven)\
**Post date:** [October 3, 2015, 4:59pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/18 "2015-10-03T16:59:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mobster\_squirrel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mobster_squirrel/32/95_2.png) [@mobster\_squirrel](https://forum.defold.com/u/mobster_squirrel)\
**Post date:** [October 3, 2015, 6:34pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/19 "2015-10-03T18:34:11Z")

</div>

> [@sven](#):
>
> Are you updating animations/positions/rotations anywhere else?

No, I’m not. If you take a look a line 26:

```
self.velocity.y = self.velocity.y + gravity * dt

```

I’m using the **delta time** to update **self.velocity.y**.

It works well on windows, with a **320x480** window, but when I scale the window up, or deploy to Android, the game runs slow.

Is there a way to include you in the list of developers, or make the project available so that you can mess around to find out what is happening?

I’d be happy to solve this. But anyways, you all have helped me a lot! 😄

---

<div class="post-metadata">

**Author:** ![mobster\_squirrel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mobster_squirrel/32/95_2.png) [@mobster\_squirrel](https://forum.defold.com/u/mobster_squirrel)\
**Post date:** [October 3, 2015, 9:16pm UTC](https://forum.defold.com/t/android-game-running-extremely-slow/285/20 "2015-10-03T21:16:54Z")

</div>

I made a little video to illustrate this…

![](https://img.youtube.com/vi/6kW-ncERUyI/maxresdefault.jpg)https://www.youtube.com/embed/6kW-ncERUyI?feature=oembed&wmode=opaque

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.

Thanks again!

[Next page](https://forum.defold.com/t/android-game-running-extremely-slow/285.md?page=2)
