[Beginner] Javascript browser game from scratch

ciro64

Destroy the turtles
Moderator
RGT Supporter
Level 5
26%
Joined
Dec 18, 2024
Messages
1,396
Level up in
1104 posts
Solutions
1
Reaction score
8,743
Points
3,477
Location
crushing turts
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.

Featured Video

Latest Threads

PSP Visual Novels

I felt this was an underdiscussed niche...
Read more

Nioh


Just ordered this looks exactly like something id play.
Read more

PS1 Obscure Games List

Hello, everyone.
I wanted to compile a list of obscure PS1 games, since the same games are...
Read more

How to deal with Video Game Overload

Hey everyone, just wanted to know how you are dealing with something I'd call Video Game...
Read more

Synthwave heaven - The Midnight

they released a banger just recently. if you don't know of them, you are in for a treat. check...
Read more

Online statistics

Members online
100
Guests online
3,289
Total visitors
3,389

Forum statistics

Threads
13,022
Messages
317,015
Members
872,815
Latest member
Berzerkarin

Advertisers

Back
Top