# Mobile games performance, let's be honest

Discussion and feedback on Construct 2

### » Tue Feb 25, 2014 1:53 pm

You have a *lot* of collision checks that look like this:

+ On collision between A and B
+ Var = 1
-> Do something

+ On collision between A and B
+ Var = 2
-> Do something

+ On collision between A and B
+ Var = 3
-> Do something

+ On collision between A and B
+ Var = 4
-> Do something

+ On collision between A and B
+ Var = 5
-> Do something

etc. etc. This example does 5 separate collision checks.

If you use subevents like this:

+ On collision between A and B
----+ Var = 1
----> Do something
----+ Var = 2
----> Do something
----+ Var = 3
----> Do something
----+ Var = 4
----> Do something
----+ Var = 5
----> Do something

That does one collision check, then does a simple check for the variable. This is literally 5x faster than the previous way, and you do this again and again and again in your events.
Scirra Founder
B
413
S
244
G
92
Posts: 25,097
Reputation: 199,802

### » Tue Feb 25, 2014 2:43 pm

I wonder, is the "Not overlapping" just as hungry as the "Is Overlapping"? Or is it more, because it's happening more often?
B
97
S
20
G
8
Posts: 1,062
Reputation: 12,725

### » Tue Feb 25, 2014 4:21 pm

An inverted overlapping condition takes the same CPU as when it's not inverted.
Moderator
B
96
S
34
G
33
Posts: 3,007
Reputation: 27,911

### » Tue Feb 25, 2014 6:32 pm

@Ashley

+ On collision between A and B (when player pick up a power up)
+ Var = 1 (this is level of power to upgrade in game store)
-> Do something (when level is high do something better)

So its my only idea how behave player when have upgraded level "var 1,2,3 etc.
It is inseparable part of the game and must be, even if this cause performance problem, I have no a better idea before how to minimize it.

B
119
S
32
G
51
Posts: 1,896
Reputation: 38,574

### » Tue Feb 25, 2014 7:37 pm

@delgado - I might be misinterpreting your post, but as Ashley said you're doing redundant work. Read up on sub events: https://www.scirra.com/manual/128/sub-events

Sub events remember the picked instances of the parent events, so you only need to do one collision check, and the sub events that compare a variable will continue to only check and act upon the picked instances of the parent event.
Moderator
B
96
S
34
G
33
Posts: 3,007
Reputation: 27,911

### » Tue Feb 25, 2014 7:49 pm

@Arima yeah i do it for all similiar colisions condition i check CPU usage and i saw no better:
B
119
S
32
G
51
Posts: 1,896
Reputation: 38,574

### » Tue Feb 25, 2014 10:42 pm

The top way requires 5X more collision checks for the same outcome.

B
71
S
25
G
20
Posts: 1,761
Reputation: 18,270

### » Tue Feb 25, 2014 11:53 pm

@Silverforce yes i understand this and i implement this, result is on upper screenshot.
Any other ideas?
Last edited by delgado on Wed Feb 26, 2014 10:21 am, edited 1 time in total.
B
119
S
32
G
51
Posts: 1,896
Reputation: 38,574

### » Wed Feb 26, 2014 12:01 am

I dunno because its worse from your screenshot, now its bonkers 80% of CPU for your events but down to 12% for your engine (before your engine was 37%)... so i really have no idea how you put your events together.
B
71
S
25
G
20
Posts: 1,761
Reputation: 18,270

### » Wed Feb 26, 2014 12:53 am

Might be able to help. Sent you a PM
B
45
S
10
G
11
Posts: 1,106
Reputation: 9,732

PreviousNext