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
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.