I have made this game here: Snap! Build Your Own Blocks
It is a simple platformer game which uses a lot of clones. It is extremely laggy though. I have tried nearly everything I can find on forums to fix it, but I cannot figure it out. Is there anything obvious I'm doing wrong?
Also, I've noticed that if you run the program without "starting" it (Click green flag, click stop button, click onscreen "start" button) the program has basically 0 lag, and it runs almost perfectly. Why is this?
it looks like you're using a lot of the generic when blocks, which does actually create a lot of lag.
Do "if" blocks within a loop make less lag?
Yes, because if you have one script that has a bunch of ifs, it doesn't run them all at once (and you can also tell what order the scripts run it)
there is a bit of a problem with lag I've noticed, usually in my projects where I'm updating the screen / state every frame, I was working on a pool game, where I had 15 objects (pool balls), each having their own xy position, xy velocity, xy acceleration, and they each need to check for collisions with each other, there's quite a bit of lag if I'm doing it in a more brute force kind of way. but if I'm conservative with my loops, and a bit clever with my arithmetic, I can have my code organized and played out so that it's ready for the next state and can do what I need quickly and efficiently.
another example is this scrolling tile engine I made in a scratch, works beautifully, collision detection and doesn't skip a beat. snap, can't keep up, at least not utilizing the same method I used in scratch. I found however that if I generate my clones, i can set their anchor to the same sprite so that they all move in unison, as opposed to updating each position every frame, I update the parent, and all I have to check for is when the tiles move off the screen I move them to the other side, update their costume, and its significantly smoother.
so yeah you will run into lag but there are ways to optimize and be smart about what you're doing so that you can avoid it. just keep trying things you'll figure it out
lol now i need to add tons of wait blocks cause its way too fast!
I think you should go with wait until, that way you're not relying on everything lining up.
I've genuinely never thought of that. That makes so much sense as to how that doesn't lag.