Finite State Machines — Game Programming Concepts Series

Welcome to a new (probably) tutorial series on the fundamentals of game programming. We are going to explore core concepts of game development such as design patterns, algorithms and data types.

Today we are looking at the Finite State Machine, an infintely flexible data construct used in UIs, AIs, World Management and much much more. In this example we implement a basic traffic light, along with callback methods.

Text version and all code used in this example available at:


Xem thêm bài viết khác:

  1. MasthaX 4 months ago

    Why not StateMachine (Singleton instance) which accepts a State (object) instead of an Enum. I think it's very bad practice in terms of software abstraction and flexibility to use these methods I believe. Surely it's good for explanation the works of a statemachine however this will teach bad things to new software devs. and will make their code be like spaghetti in no time.

  2. Jonah Dominguez 4 months ago

    its scarier than it is??

  3. Aaron Wiggan 4 months ago

    More please!!

  4. Friendship Buddies 4 months ago

    how can you simultaneously say "F(eye)nite state machine" and "f(in)ate" number of values

  5. nicebagel 4 months ago

    Please continue this series, it's very helpful to learn these abstract concepts that are not unique to a particular engine or language

  6. MaKu X 4 months ago

    how to use FSM in construct 2 or 3??? please help

  7. Aaron 'Marth8880' Gilbert 4 months ago


  8. Arturo Ordonez-Hernandez 4 months ago

    I think for a default case we could say "The power went out" or something.

  9. Riefky Maulana 4 months ago

    thanks, good explained. please make more videos of this serie!! 🙂

  10. FalcoGer 4 months ago

    why would you use a delegate and events when you could just use a get function?
    I'm a bit confused. this opens up a whole can of worms with thread safety. if you were to check at the end of each frame if the state has changed you could get the state and act accordingly then. instead of in the middle of the frame, something happens, state changes and then you call all this code which will probably have to do plenty of cleanups. and suddenly you end up with

    <— event fired, call thread here
    unit = NULL;

    and you've got yourself a nice random access violation

  11. Trevor Belmont 4 months ago

    Thanks. Simple and straightforward. I like that you used actual code for explaining instead of confusing and boring diagrams used by other yt tutorials when explaining fsm

  12. Clayton Weaver 4 months ago

    So you didn't end up doing the Game Programming Concepts Series? That's a shame.

  13. syntax_error 4 months ago

    very usefull thanks …

  14. Rudrangshu Nandi 4 months ago

    Please keep on creating this kind of algorithm series. They are super helpful and you explain pretty well.

  15. Cort Smith 4 months ago

    Why do you pronounce enum "enoom" while other programmers pronounce it "e-num".

  16. Brian Haddad 4 months ago

    This was a great first video in a series I will look forward to seeing more of.

  17. cripplord 4 months ago

    Really like the idea of this series and think it would be incredibly useful as its useful to everyone no matter what language, engine or platform they are on. I do think it would be a good idea to possible cover Goal orientated action planning (GOAP) as its becoming more popular over finite state machines due to the poor scalability of FSMs.

    As for design patterns such as singletons i think they would be very beneficial to many new developers i also think the factory pattern and strategy pattern are always extremely good to know as a developer.

    Final suggestion, one area that seems to get severely overlooked (even on my degree it was never covered) is a detailed overview of debugging techniques and tools. its shocking how many programmers on my degree had no idea how to set conditional debugs, handle threaded debugging or use the immediate windows in visual studio etc yet its extremely handy to know.

  18. aiokos 4 months ago

    This series is exactly what I was looking for. Thanks for making these!

  19. garoslaw 4 months ago

    Thank you, I always wonder how to do that kind of stuff. Really hoping to see more of those. 😮

  20. Luis Torres 4 months ago

    I actually really like this! this video gave me a good idea on how to implement a feature I want to add in one of my own games, for some reason I never thought to use the concept of states! I think you should keep the videos coming since, even though you don't necesarily go into heavy code, you are talking about some of the core concepts that you should understand for developing a video game.

  21. Fab Slab 4 months ago

    Windows and you didn't use Visual Studio?

  22. Sandor Fejer 4 months ago


    First, I like your channel, that's why I have subscribed.
    Second, on this video I will split some hairs a little bit. Maybe I'm software engineer for too long but:
    – you chose states based on visuals, we do that rarely, better if you build upon the logical states like:
    Traffic lights logic states
    – Traffic lights off (visual: flashing yellow, meaning: dangerous junction)
    – stop traffic (visual: red)
    – prepare for run traffic (visual: red & yellow, in countries where the manual gears are the majority)
    – run traffic (visual: green)
    – prepare to stop (visual: yellow)

    This allows you to build a pedestrian traffic light upon the structure as well:
    – traffic lights off (flashing pedestrian symbol, also dangerous junction)
    – stop (yellow pedestrian or Don't walk, or red standing pedestrian – in Europe)
    – prepare (no state jump to next)
    – run traffic (white walking pedestrian or green walking pedestrian or Walk)
    – prepare to stop (flashing yellow pedestrian, flashing green walking symbol or flashing walk)

    And there you go. I think it is better to teach people the abstraction from day 1, because later it will be harder to wrap their head around it. And you can separate the visuals from the logic as much as you can.

  23. dn 4 months ago

    Can't wait for more of this series!

  24. Marten V 4 months ago

    Covering stuff like this really helps me out. I would love to see more of this!

  25. ZeroCoolIsGod 4 months ago

    I love your Chanel dude. It's free content, your voice is excellent, your research is on point. Finish one god damn series please. What you have created has been immeasurably helpful to my development as a programmer, and this is one of the few channels I check regularly for updates, but my desktop is littered with your abandoned projects.

  26. Paul Hunnisett 4 months ago

    really enjoyed the video – keep them coming, this could be a really useful series!

    Am I not right in thinking, however, that, in Java at least, enums are very inefficient? Using a set of final static values would be better, albeit less elegant. Agree/disagree?

  27. czesiobar 4 months ago

    The idea about presenting some algorithms and design patterns seems great. For me as a beginner game developer this would be very useful. Keep up the good work! 🙂

Leave a Comment

Your email address will not be published.

You may also like