Need help optimizing PVZ

I’m making a demake of PVZ, and with this being makecode, performance is a really important part. It isn’t laggy right now, but it definitely will be as the project gets bigger, and all the inefficiencies will add up, so I’d like some help making my code more efficient. You can find the project here:

https://makecode.com/_gHEW76gTKA0Y

Thanks!

4 Likes

I don’t really know how to optimize it, but I wanted to say that the game looks super good so far!

1 Like

this looks really cool

1 Like

unsure if this would work or not but keep it to as little blocks as you can (or as little functions)

1 Like

I’ll try, the main thing that causes lag is 1. too many loops being called every frame and 2. too many sprites, like over 200-300

I did not check the code, but make animations with arrays, and the less frames the better.

Also, THIS IS AMAZING! The best remake of PvZ I’ve seen yet.

1 Like

When I was playing I maximized the amount of sprites to observe the frame rate, which was at nine .if there was a zombie raid at my house this is the army I would call…

1 Like

Thanks! But how do I make the animations arrays, and how does doing that improve performance?

9 fps is way lower than I thought it could get. did you change the code, cause how did you plant two repeaters on the same tile?

I dont know check this code by @Brohann : https://arcade.makecode.com/88716-83372-59481-28916

And it improves performance because animation blocks are very laggy in editor. Honestly idk as well but i know it improves performance (maybe? just try it with one of the animations in a copied version to compare)

2 Likes

I didn’t change anything with the code. I just added fps so I can see the rates but then I removed it. Im thinking the more sprites you have the lower the fps gets. But I once did animation arrays so here’s how to do that. (warning be prepared for a paragraph worths talk)

So first things is to go to extensions and type “Animation”. Once thats done click into it and drag or type, animate [mySprite] with [frames] interval [500] ms loop [ON] Btw I don’t know what you want for animation arrays, I already see that you have animations for the plants. Are you talking about adding animations to zombies? If your talking about adding just frames here’s the code for that. drag or type, set list to array of [image. Then put out what you want for frames. For example Zombie, Or Just an animation for the plants.

That’s all the help I can offer. Hope that helped

1 Like

Thanks, I’ll see if this works

1 Like