too many invisible triggers? lag!

Get help using Construct 2

Post » Fri Jun 21, 2013 4:08 pm

Hi guys,

I have this platformer game, where you have zombies and they just go back and forth on a platform right, typical platformer. Now the algorythm behind it is that I have these invisible triggers, which on collision with a zombie, mirror the zombie and make it move in the opposite direction.
The problem is that when a level is big enough (9000x2500 for example) and I have many of those triggers (20 for ex.) the game starts to lag when I built in on iPad using cocoonJS. In the event sheet I have

"ZOMBIE on collision with 'goright' >>> mirror zombie, set direction to RIGHT"
"ZOMBIE on collision with 'goleft' >>> NOTmirrored zombie, set direction to LEFT"

My question is, how exactly does the "on collision" work in the algorythm? I've tested the game and in the levels which don't lag, if I add some triggers somewhere on the map, it starts to lag. My thoughts were that each of every zombie checks for every trigger there is on the map per tick - so when those triggers accumulate, the zombies have to check for all of them and the game slows down. So the fact that those triggers have an effect is there. But I still wanted to make sure if that's how "on collision" works, since it's a one time event. If it was "when overlapping" then I'd be sure that it is checked per tick, but in "on collision" case I'm not sure so I wanted to make sure and thus made this long ass post for which I apologize :D

Also, if that's the case, do you guys have any idea how to go around this? I though of making it so that the zombies check only in the certain area around them, so they don't reach every trigger on the map but i'm not sure how to implement that yet.

Anyway, all the feedback is appreciated as always, sorry again for the length, I just wanted to share my thoughts on it and state the problem clearly :D
B
6
S
1
Posts: 32
Reputation: 789

Post » Fri Jun 21, 2013 4:42 pm

It doesn't sound like that should be making it slow. If you disable the events, does it go faster?
Scirra Founder
B
378
S
220
G
84
Posts: 23,871
Reputation: 188,227

Post » Fri Jun 21, 2013 4:46 pm

It might be worth adding a nearest/furthest event. It sounds like you zombies are checking all the points they could collide and not just the ones there near.
Might also be worth adding in some local variables on the zombie and the collision point. If zombie.variable = 1 collides with trigger.variable = 1 then run the action.
Ether way you shouldn't be receiving a lower framerate due to checks.

My final piece of advice would be to send in a capx to the lovely people here and have them look through your code just to make sure you haven't left in "every tick behaviors" that don't need to be there.
There could even be a solution in using the family behaviors but I don't have any experience there.
Let me know how you get on as this subject has intrigued me.
B
13
S
2
Posts: 87
Reputation: 1,244

Post » Fri Jun 21, 2013 5:06 pm

Maybe you should be looking at how you are moving these zombies rather than the triggers...

20 triggers is not much, but it may be enough to tip the performance over the edge if something is not optimised elsewhere...
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Fri Jun 21, 2013 5:57 pm

Might I also suggest that on such a large layout that you place invisible trigger blocks so that when the player hits the blocks the nearest zombies are spawned. Then there is no checking until the zombies are spawned. And you aren't wasting ticks checking for things that the player can't even see at the time.BluePhaze2013-06-21 17:58:33
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,538

Post » Fri Jun 21, 2013 9:24 pm

(we are both working on this)

this is image of all zombie events


there is spawner, when player is within range it spawns zombie

zombie moves left or right and changes direction when hitting special triggers.

hellwalker2013-06-21 21:31:11
B
24
S
7
G
3
Posts: 138
Reputation: 2,795

Post » Sat Jun 22, 2013 3:00 pm

Here is a Cap file, if anyone could look at and see if we do something very wrong that would be great, thanks in advance
https://dl.dropboxusercontent.com/u/1248743/WashingtonVSZombies-fps.capx
B
24
S
7
G
3
Posts: 138
Reputation: 2,795

Post » Sat Jun 22, 2013 3:24 pm

For what it's worth it runs brilliantly on Chrome.

Your problem might, and use the term jokingly, come from the fact that at any given time the game is handling 500+ objects.

This is pretty easy to cut down, firstly you can use a library layer to store all the objects your current layout isn't using.

The number of enemies could also be decreased, I was completely swarmed out of the gate and would never have got past the second group if I hadn't realised that touching your health bar clears the screen of enemies (A feature I imagine won't make it to the final build!)

Maybe trim the particle effects a little bit? When your triggering it for every attack and reaction and can imagine it adding up.

Overall though I really liked the game! Nice spin on the whole Abe Lincoln Vampire hunter deal!
B
53
S
16
G
8
Posts: 628
Reputation: 8,609

Post » Sat Jun 22, 2013 4:12 pm

few things I noticed in a quick look over it,

many of your background sprites have collisions enabled and there is no need for them to have

your zombie movement change triggers could be much smaller and still be as effective (I still think a trigger once action with variables as triggers would be better here)

many of your weapon sprites have upto eight points in their collision "boxes" most would be fine with 3

particles are a performance killer..maybe make a sprite to look same and use that instead...

This did run at 60 fps on chrome for me though...
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Sat Jun 22, 2013 4:55 pm

yeah, it lags when built on iPad using cocoonJS, on Chrome it runs ok, thanks for the massive feedback guys, we'll try everything you've mentioned so far and get back to you!
B
6
S
1
Posts: 32
Reputation: 789

Next

Return to How do I....?

Who is online

Users browsing this forum: AllanR, rayray, RetroSpock and 8 guests