Discuss Scratch

bedwars_sweat_27
Scratcher
37 posts

Help reducing tile engine lag

https://turbowarp.org/732103535

Use turbo warp since it can access unshared projects and I don't want to reveal this project yet by sharing it.

Note that turbowarp is built to make Scratch projects run faster and it works. It TRIPLES the FPS for my game.

On my school Chromebook the normal Scratch version runs at 4 FPS, which is just barely playable. On my (fairly high-end) PC at home, it runs much better at around 10 FPS, however, I do not want accessibility to be an issue. Also, but since I adjust the speed of some things based off of FPS (to make the player walk equally fast no matter the lag), some attack animations do not get a chance to play and therefore do not hit the enemies, which can be a problem.

Can someone help? I already only draw tiles visible to the player, which definitely helps but only until I try to make maps big enough to be playable.

The tile engine is in the “world” sprite, the “redraw” block.

Thanks!
Spentine
Scratcher
1000+ posts

Help reducing tile engine lag

The reason it's slow is because you're checking every tile if it's on the screen. Just use math to find the tiles that are on the screen, and then render those. What you're doing is checking about 10K tiles if it's on screen, twice. That's going to take a hit.

You can use modulo, floor, and division operators in order to calculate what tiles are on screen.

I'm too lazy to do it though, maybe another kind person would like to do it!

Last edited by Spentine (Sept. 17, 2022 20:56:28)

bedwars_sweat_27
Scratcher
37 posts

Help reducing tile engine lag

Spentine wrote:

The reason it's slow is because you're checking every tile if it's on the screen. Just use math to find the tiles that are on the screen, and then render those. What you're doing is checking about 10K tiles if it's on screen, twice. That's going to take a hit.

You can use modulo, floor, and division operators in order to calculate what tiles are on screen.

I'm too lazy to do it though, maybe another kind person would like to do it!
I was thinking that too, however I couldn't find a way to do it.

Now that you mentioned the modulo operator, I have an idea now!

Thanks!
bedwars_sweat_27
Scratcher
37 posts

Help reducing tile engine lag

bedwars_sweat_27 wrote:

Spentine wrote:

The reason it's slow is because you're checking every tile if it's on the screen. Just use math to find the tiles that are on the screen, and then render those. What you're doing is checking about 10K tiles if it's on screen, twice. That's going to take a hit.

You can use modulo, floor, and division operators in order to calculate what tiles are on screen.

I'm too lazy to do it though, maybe another kind person would like to do it!
I was thinking that too, however I couldn't find a way to do it.

Now that you mentioned the modulo operator, I have an idea now!

Thanks!
Alright sadly I still can't figure it out. You're definitely on to something, however, I just can't figure out how to actually do this.

Last edited by bedwars_sweat_27 (Sept. 17, 2022 21:51:29)

bedwars_sweat_27
Scratcher
37 posts

Help reducing tile engine lag

bump because I never managed to solve it
legendary34678
Scratcher
1000+ posts

Help reducing tile engine lag

Try to only bump a post if it's been 24 hours since the last post. Someone will get to your topic eventually.

Powered by DjangoBB