Lag Spikes When Creating Objects

Discussion and feedback on Construct 2

Post » Fri Aug 12, 2016 3:12 am

Hi

I'm creating a survival game (mobile)
so the player must kill a lot of enemies to get the highest score

The problem is, when i tried to create the enemies, maybe (~10-20 per wave). There's a lag spikes (dropped the fps from 50-60 to 30 - 40).

I put all of my enemies sprite into a different layout named "bank"

I read on the forum that i must put the sprites that i want to create outside of "THAT" Layout.
I cannot put it on different layout (in my case "bank" layout).

When i tried to put the enemies sprite outside of the game layout and destroy it at start of the layout,
the player_kill_counter variable is counting the enemies that destroy outside of the object
because, my event sheet for killing is

Enemies on destroy -> add +1 to player_kill_counter variable.

So how do i do this?
Thanks in advanced :P

Image

http://imgur.com/a/pkyLg
Last edited by hsetiawan on Fri Aug 12, 2016 9:54 am, edited 1 time in total.
B
41
S
21
G
27
Posts: 39
Reputation: 17,252

Post » Fri Aug 12, 2016 8:41 am

How are you creating your enemies? In a loop? One at a time over X seconds?

How complex are the enemies? Are they made of several parts, or just a single sprite? Are they effect heavy?

How many other objects are in your layout? Are those effect heavy or doing complicated movements/animations? What is the total object/sprite count?

To give more accurate information we need to know more specifically about the problem. There is likely a bunch of ways to optimise the events to make it run smoother - but without knowing more, or having a capx or even an event sheet screenshot to look at, it's difficult to really say for sure.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Fri Aug 12, 2016 9:59 am

SoldjahBoy wrote:How are you creating your enemies? In a loop? One at a time over X seconds?

How complex are the enemies? Are they made of several parts, or just a single sprite? Are they effect heavy?

How many other objects are in your layout? Are those effect heavy or doing complicated movements/animations? What is the total object/sprite count?

To give more accurate information we need to know more specifically about the problem. There is likely a bunch of ways to optimise the events to make it run smoother - but without knowing more, or having a capx or even an event sheet screenshot to look at, it's difficult to really say for sure.

~Sol


Hi, sorry for not posting a screenshot

Just updated the post with the screenshot of the code

-The enemies are checking the distance of itself and the player, if the enemy is in distance, the enemy attacks the player
-For right now, the object count is 230 (without the enemy & tilemap for my background)
-The animation for each enemy is only 3-4 animations with 1-8 frames.
-Using the brightness effect (so when the enemy got hit, they blink to white for a second)
B
41
S
21
G
27
Posts: 39
Reputation: 17,252

Post » Fri Aug 12, 2016 11:29 am

What device are you testing this on? It doesn't look like it should be causing ANY problem for fps, at least as far as I can tell from the events you've shown.

What size are the sprites you're using? Is this all lo-fi graphics or more HD style?

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Fri Aug 12, 2016 12:12 pm

SoldjahBoy wrote:What device are you testing this on? It doesn't look like it should be causing ANY problem for fps, at least as far as I can tell from the events you've shown.

What size are the sprites you're using? Is this all lo-fi graphics or more HD style?

~Sol


(Without the Enemy Spawning Yet)
Ipad 2 = 30-50 fps
Nexus 5 = 50-60 fps
Iphone 4 = 5 fps :(
Iphone 5 = 50-60 fps
Iphone 5s = 60 fps
Iphone 6s = 60 fps
Samsung Galaxy Note 3 = 50-60 fps

(When the enemy spawn)
Ipad 2 = 20-40 (~20 when the enemy being spawn, after all of the spawning is done, the fps become 30-40)
Nexus 5 = 50-60 fps (~30 when the enemy being spawn, after all of the spawning is done, the fps become 40-50)
Iphone 4 = 5 fps :( (Cannot even move)
Iphone 5 = 40-60 fps (~40 ish when enemy are spawning, and 50-60 after spawning is done)
Iphone 5s = 60 fps (~45-50 ish when spawning)
Iphone 6s = 60 fps (~45-50 ish when spawning)
Samsung Galaxy Note 3 = 50-60 fps (~30-45 when spawning)

The problem is the lag when spawning for a few seconds

Not placing all used objects in the layout
If objects are not placed in a layout but are created by events, Construct 2 will load the textures for those objects the moment you create them. This can cause a momentary pause or "jank" and make the game feel less responsive. This can be avoided by placing any used objects in the layout. They can be placed off-screen and destroyed on startup to avoid interfering with the gameplay. Then Construct 2 will preload all their textures when the layout starts, avoiding any "jank" as they are created and destroyed at runtime.
B
41
S
21
G
27
Posts: 39
Reputation: 17,252

Post » Fri Aug 12, 2016 12:23 pm

The fps looks respectable on devices less than 3-4 years old... that's not bad really.

Still you don't mention about the resolution you are using for sprites and things like that. A handful HD graphics will perform a lot worse than thousnads of lo-fi "simple" graphics.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Fri Aug 12, 2016 12:29 pm

SoldjahBoy wrote:The fps looks respectable on devices less than 3-4 years old... that's not bad really.

Still you don't mention about the resolution you are using for sprites and things like that. A handful HD graphics will perform a lot worse than thousnads of lo-fi "simple" graphics.

~Sol


It's a small project

The Game Layout is 320x180
The Enemies sprite is vary from 16x16 to 48x48 only
B
41
S
21
G
27
Posts: 39
Reputation: 17,252

Post » Sat Aug 13, 2016 3:31 am

Yeah you shouldn't be getting lag like that... something else isn't right.

Do you have some open ended loops running, or maybe some conditions that are being checked too often that perform complicated actions?

Without seeing your capx file it's going to be practically impossible to say for sure.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499


Return to Construct 2 General

Who is online

Users browsing this forum: BobOfAMillion and 8 guests