Mobile game lag

EDIT: I put the images in a RAR file because I couldn’t put them directly in the post x_X

Hi,

I’m actually developing a mobile game, everything was going smooth while testing it on PC but when I test one scene on a smartphone It became laggy, on my phone it was annoying but playable but on a friend’s phone it was totally unplayable.

here is the scene:

Look at image 1 and 2

As you can see there aren’t too many objects. The violet and orange squares are hidden and their fuction it’s to create an object when a condition it’s satisfied (a timer reaches a value and the player is in a have X distance from the creator object). This objects moves infinitely as the player moves. Like this:

Look at image 3

I Followed this same logic to move infinitely the backgrpund, the squares and the platforms and I noticed that lag occurs in my phone when the player is at the position that the squares and the rest should move.

Other thing that is constantly in work it’s a condition where after a timer reach a value it generates a ramdom number between 0-3 which decides what animation will have the object that creates one of the squeres (a Power Up). I’m doing that like this:

Look image 4 to 7

My question

What should be causing the lag?

Am I trying to achive what I want in the wrong way?

I’ll appreciate your help :slight_smile:
Gdev forum question lag.rar (285 KB)

It difficult to tell.

The CPU consumption of your game on gamejolt is somewhere around 300MHz which is good but during gameplay it sometime go as high as 1GHz which s a bit too high in my opinion.
The memory consumption of your game is somewhere around 200MB RAM
The VRAM consumption of your game is also around 200MB VRAM.

It is definitely make it difficult to play or even unplayable on devices with less than 1GB RAM and 1.x GHz (300-400MHz / core) CPU.

To keep the CPU consumption low, try to trigger events only when they needed. For example, trigger an event on an object only if the object exists and only once or only limited time / second if it doesn’t need to be triggered every frame.
To keep the memory consumption low, create objects only when you need them and delete objects when you don’t need them and try to use small images instead of scaling big images down to the size you need and also use object variables whenever you can.

But really, if performance is important to you, HTML5 is the possible worst way to go but in case you prefer HTML5, I suggest Cocoon with Canvas+. It is provide almost native performance but it is less compatible and also the free account comes with limitations but from my experience this is the best way to go if you need good performance using HTML5 on mobile:
cocoon.io/

Just put timers on events so you only call them as often as you need and not on every frame and you will see a huge performance boost.

Mats can I ask you for personal help of a game?

I can’t offer individual help, however, I could take a look at your code and make a general “how to optimize your game” kind of tutorial for everyone. Chances are, things that can be done to optimize your game can be applied generally. I can do it without sharing your code* if you wish for it to remain closed-source.

*I won’t need to share your code at all.

Anyway, if you’re happy with that, send me a PM with your gdg file and images in a compressed folder, otherwise, a general optimization tutorial will probably appear eventually that can help you, or, you can continue to ask questions in this thread but be a bit more specific so we can help.

Sorry for checking late this and thanks a lot for the answer!

I actually noticed that the problem was that if there where like 5 or more objects when the speed of the objects incress too much and quickly it cause that… why I don’t know for sure but I just slow the objects and problem solved :slight_smile:

You should also make use of subevents more.

In your event 124, you should put:
trigger Once
----- layer is visible
---------- pick an object
----------------- variable = something
---------------------- another variable = something → do your stuff

That way, GD won’t check several conditions all at once, and will stop the process earlier than with a bloated conditionnal box.

Cool thanks for the info! I’ll made those changes

Can you be more specific please? I have the same problem