[Beginner] Javascript browser game from scratch

ciro64 ciro64

Castlevania 64 apologist
Moderator
RGT Supporter
Level 5
Joined
Dec 18, 2024
Messages
1,416
Solutions
1
Reaction score
6,205
Points
3,477
Location
Brazil
I made a tutorial!


I introduce concepts one by one. Or rather, I throw them at you and you see immediately what it does. It's not a proper introduction to programming concepts in a more isolated way, so people who never touched code before might feel a little overwhelmed. For that reason, I intend to do another tutorial bridging that gap if my motivation keeps up, and then more advanced ones after that.

Let me know what you think of it, or if there's any problems or questions.

Thanks for reigniting my gamedev passion, RGT! ::terriermon-happy
 
I would have used requestAnimationFrame instead of setInterval

The frequency of calls to the callback function will generally match the displayrefresh rate.

For that specific reason

 
I would have used requestAnimationFrame instead of setInterval
I think the main goal in this tutorial is to provide a general idea about how things would work for beginners.

Using requestAnimationFrame is better, but i think it can be considered as a technical detail.

I think this tutorial is well designed overall, and fulfills its purpose. 👍
Also, ciro64 said he might create more tutorials to fill the gaps. ::coolstafy
 
I would have used requestAnimationFrame instead of setInterval



For that specific reason

Thank you for looking at the tutorial!

I decided to use setInterval for the sake of simplicity.

If I used requestAnimationFrame instead, I'd either have to:

  1. Multiply the movement with delta time. While it would have been fine for this game, I plan to make tutorials that build on top of this one, introducing concepts of acceleration, gravity and platforming. In those more complex cases, it's a bad idea to use delta time in the logic loop because it introduces instabilities in the game physics, which can affect the gameplay quite a lot.

    I don't think delta time is a bad thing on its own, but I've seen tutorials and even game engines in the past create a bad habit in developers by encouraging them to use it everywhere.
    .
  2. Handle the drawing at every requestAnimationFrame call and the game loop in some other way. A good way I found to do this is to calculate how much time has passed from the last animation frame and advance logic frames accordingly. This method also compensate for stutters unlike setInterval.

    But like @JustLooking123 said, I want to keep things simple by introducing them one by one. But in a future tutorial, I might introduce complex loop handling.
 
I think the main goal in this tutorial is to provide a general idea about how things would work for beginners.

Using requestAnimationFrame is better, but i think it can be considered as a technical detail.

I think this tutorial is well designed overall, and fulfills its purpose. 👍
Also, ciro64 said he might create more tutorials to fill the gaps. ::coolstafy
I understand that, setInterval is definitely the most concise and straight forward approach, however animation stuttering tends to ruin everything, no matter how well your sprites look, no matter how hard you tried to optimize the rest of the code, end result still is disappointing and there's nothing you can do about it, except sync with refresh rate...
 

Users who are viewing this thread

Connect with us

Support this Site

RGT relies on you to stay afloat. Help covering the site costs and get some pretty Level 7 perks too.

Latest Threads

Which Final Fantasy IV Complete Collection should I download?

There is two different game of FFIV Complete Collection. One is version is Japanese and the...
Read more

Best 2000s board game/ tabletop game

It doesn’t have to be from the 2000s just one you remember playing back then
Read more

So I just saw the 343 Halo lore retcon

I love Halo, probably one of my favorite games of all time. I even defended 343 back in the days...
Read more

Raiden V

1748734421151.png


Discovered this tonight been playing Raiden III and IV if its any good i might snap...
Read more

Actually good Android games?

Very often I find myself wishing there was something to play on my phone while I wait, but...
Read more

Online statistics

Members online
158
Guests online
269
Total visitors
427

Forum statistics

Threads
8,547
Messages
214,877
Members
659,882
Latest member
idkwhoami

TOP Supporters

Top Supporters
Back
Top