Anybody know why my game is so laggy?

Here is my game

some people might recognize this one, and I tried to keep fixing bugs myself so I didn’t have to annoy people with the same game over and over again. But I keep seeing that my game is so laggy and that sometimes the projectiles you shoot don’t even go anywhere. Could someone please help? Thanks

1 Like

It’s probably the crap-ton of sprites you create on the start of a wave
using “show stats” the sprites skyrocket and the FPS drops.

Its so laggy because of the insane amount of sprites you have in the game at one time

in level one you have 300!!! SPRITESSS

Ohh… that makes sense, the problem is that I need a lot of sprites for you to fight, or else it’ll be really boring :face_with_diagonal_mouth:

then don’t spawn them all at once

Here’s the trick: in a game update, detect if they are within half the screen size plus a little of the player, and if they aren’t, destroy them but use place a specific tile where they are destroyed. In the same game update, detect if you are within range of the tile, and if you are then spawn a sprite on top of it and remove the tile. This way you won’t have 300 sprites at one time in the game; it will be more like 15 or so, and to reduce lag even more you can use a variable to detect how many sprites are in the screen; if over 15 or so then don’t spawn sprites on in-screen spawn tiles. You’ll now have 300 sprites in one level, but only a few showing at once.

I already fixed this, I just made it so that the enemies die when you aren’t in range and reduced the amount that spawn. I actually did this while fixing a problem where you can just walk away and there won’t be any enemies to fight.

1 Like