Part 3: Game State Manager - Make Video Games w/ LibGDX: Flappy Bird

Sdílet
Vložit
  • čas přidán 15. 06. 2024
  • Making Flappy Birds from start to finish using Java and the LibGDX Framework. The result being a game that runs on multi-platforms including: Android, iOS, Desktop, and Blackberry!
    Learn about game-loops, textures, Orthographic cameras, and game worlds!
    Please feel free to ask questions, I am always willing to help when needed!
    If you are feeling generous please help by donating to my patreon page... This helps me spend more time producing content that I otherwise wouldn't be able to:
    / brentaureli
    source: github.com/BrentAureli/Flappy...
  • Věda a technologie

Komentáře • 78

  • @jordanhanley7585
    @jordanhanley7585 Před 6 lety +35

    For those of you that are getting errors from the following line "states.peek().update(dt);"
    You need to first create the menuState class and push that state on top of your stack of states. If you try to peek the top of the stack when there is nothing in it you will get an error. Also since State and its methods are abstract you cannot call them on the State class itself, this is why the menuState is needed, so those abstract methods can be defined and actually have a purpose.
    Like so others can see
    Like so others can see

    • @Tenecifer
      @Tenecifer Před 4 lety

      Thank you

    • @mickb5620
      @mickb5620 Před 2 lety

      Thanks a lot, you saved me another two hours of my evening lost on this problem haha

    • @mearlixxx
      @mearlixxx Před rokem

      What should I do in class Menustate?

  • @sorcey9532
    @sorcey9532 Před 8 lety +44

    I still don't know what I'm doing but I feel like a pro

    • @sorcey9532
      @sorcey9532 Před 8 lety +1

      ***** Yeah definitely I'll keep on this

    • @ShadowAnimeation
      @ShadowAnimeation Před 7 lety

      +Sorcey Try the SoloLearn Java App, it was informative but quick to get through. I got through it in like two days and it helped me so much with understanding some of these concepts better.

  • @ruthbugembe6746
    @ruthbugembe6746 Před 6 lety

    You have made the stack staff effortlessly easy to understand. Thank you very much

  • @syszee
    @syszee Před 7 lety +1

    I'm sure you've already answered this, I just can't find anything on it. Is there any reason why not to use the built-in screen (state) system LibGDX has and instead create a custom one from scratch. From what I can tell its just recreating the will. Is there any real benefit? Thanks in advance!

  • @batkomahnoX100
    @batkomahnoX100 Před 8 lety

    Very good tutorial. Easy to understand and presentation is done very nice.
    Thanks for sharing your knowledge!

  • @Eselfar
    @Eselfar Před 4 lety +1

    That's a nice clean code. Love it!

  • @tbooonetwo-fitty-five7523

    Oh my god your mechanical keyboard is making me very satisfied. I hear some blues :), what keyboard do you have?

  • @sekont15
    @sekont15 Před 8 lety +1

    Thanks is rly good tutorial ;)

  • @nivsaparov1
    @nivsaparov1 Před 8 lety +1

    Thank you so much !!!

  • @GawblyOG
    @GawblyOG Před 7 lety +2

    How much learning time from scratch did it take you to become able to create games like this?

  • @stride7860
    @stride7860 Před 8 lety

    Hey Brent! Just starting to go through your videos here and I'm curious if you know of any documentation for some of these classes that explain things in a bit less verbose way.
    Much of the documentation for some of these classes is more technical than it needs to be to explain what the use of classes are.
    I'm referring to the classes like Gdx.gl.glClearColor and Gdx.gl.glClear for now, but just generally speaking I'm trying to find some good documentation. Or maybe you have a better suggestion to learn these classes?

  • @mandy1339
    @mandy1339 Před 6 lety

    This tutorial is very fast paced. Is that intended? Sometimes it's even hard to time pausing the video before he changed the screen. Also Thanks for making these.

  • @NLogSpace
    @NLogSpace Před 9 lety

    Hey, thanks for your videos! One question: Why do we pass the delta time to the update method? Shouldn't game logic always be independent from the rendering? Maybe in a small game like this, it doesn't matter, but for larger projects, this could lead to non-deterministic behaviour. Especially for online games this could be a problem, no?

    • @NLogSpace
      @NLogSpace Před 9 lety

      Yes, I understand that we do update and render seperately.
      But still, the update method takes the delta time of the graphics, so we update the game objects depending on this delta time, which is slightly different every cycle.
      So it would surprise me if this is the standard approch, since it leads to non-deterministic behaviour: Even with the exact same inputs, the game could behave different every time.
      I feel game logic should be updated in fixed timesteps like exactly 1/60s to assure determinism, while the render should use the delta time to draw the objects at their appropriate positions.

    • @NLogSpace
      @NLogSpace Před 9 lety

      ***** Thanks for your answer and the resources, very helpful! Would be great if you cover this concept in a future tutorial. :)

  • @compsbecomping
    @compsbecomping Před 8 lety

    Hey, i've been watching this series and it's been really helpful.
    One thing that i am puzzled about is the purpose of the update() method. Why do you create this method?
    As in your videos, i put the handleInput() into update() in all of my states, however, i've come to the point where I need to draw to the screen inside the handleInput() and I can't because handleInput() doesn't get access to the SpriteBatch. What I'm trying to ask is what is the reason for doing "gsm.update(delta)" instead of "gsm.render(batch,delta)" and deleting update() alltogether ? ... And then in the state, pass both those arguments to handleInput() inside the render() method ?
    As an observation, if i commented out that update call in FlappyDemo and then moved the handleInput() into the render method of all the states, everything still worked perfectly.

  • @cazino4
    @cazino4 Před 4 lety

    Does the Render process run on the "main" JVM thread or is an alternate thread spawned when the game boots??

  • @hdtsoft6994
    @hdtsoft6994 Před 8 lety

    Hi,i've a question about the Gameloop,because i dont see anything like it,there is no while loop or something. Or does the system automatically loop threw all the objects?

  • @farooqabbas4514
    @farooqabbas4514 Před 7 lety +2

    Hi
    My code is working but I could not understand how this render in GameStateManager function works
    public void render(SpriteBatch sb){
    states.peek().render(sb);
    }
    particularly why we are doing this stuff states.peek().render(sb);

  • @opentech5972
    @opentech5972 Před 5 lety

    Which design pattern is this ? i mean for GameStateMachine..
    ty for videos btw.

  • @juststudyit9995
    @juststudyit9995 Před 7 lety

    At 3:32 , { states.peek().update(dt) } , is the update(dt) the method inside the State.java file?

  • @NabeelAbbasnbl
    @NabeelAbbasnbl Před 8 lety

    What difference would it make if I use Intents instead of a State Stack? Will That work?

  • @vladislavzabinskij2685

    Hello, Brent. I've only wrote 1 game in libgdx, so I don't get why don't you use class "Screen" and "Game" in your game. Is there any reason to use your conception of representation screens. Please answer, i need it.

  • @MarcoFalanga
    @MarcoFalanga Před 7 lety +1

    Hi Brent, great tutorial.
    I have a problem in GameStateManager class when i run the game i have an error on the peek method of Update.
    Can you help me??

    • @DavePark
      @DavePark Před 7 lety +3

      Did you remember to uncomment everything from the State class?

    • @bruno.myrrha
      @bruno.myrrha Před 7 lety

      Oh this is why my program was importing some State library. Called mine States instead of State. Thx for the help man =D

    • @Rodrigoheroin
      @Rodrigoheroin Před 7 lety

      Yeeeeah, thank you

  • @silvernoob8688
    @silvernoob8688 Před 7 lety

    Who gets an error on Sack - use Stack or private java.util.Stack states;

  • @silvernoob8688
    @silvernoob8688 Před 7 lety

    who gets a compiling error - fix the main class, remove public and better copy the code from source and paste it with you corrections. DIsable instant run as well.

  • @maxwhatupman
    @maxwhatupman Před 8 lety

    This should all make sense in the end, right?

  • @jmonkey2150
    @jmonkey2150 Před 8 lety

    my State dont work every time i do the thing i gives me options to import stuff and if i do i get errors

  • @jaysanprogramming6818
    @jaysanprogramming6818 Před 4 lety

    If glClear erase everything on screen then why not remove completely glClearColor? Is there a reason to keep it?

  • @ericpalmer5168
    @ericpalmer5168 Před 6 lety

    How would I use a fixed timestep instead of getDeltaTime?

  • @ridhwaanany7480
    @ridhwaanany7480 Před 8 lety

    could u please explain why we have to update delta time ? ELI5 please

  • @jeraldpierucci3864
    @jeraldpierucci3864 Před 7 lety

    Im getting a Error:gradle execution failed for task ':core:compileJava'.
    Im also getting
    Error:(21, 13) Gradle: error: cannot find symbol method push(State)
    Error:(30,13) Gradle: error: cannot find symbol method pop()
    Error:(31,13) Gradle: error: cannot find symbol method push(State)
    Any help would be awesome

  • @McMurchie
    @McMurchie Před 7 lety

    Does anyone know why it is flagging up the tates.peek().update(dt) as being a problem with dt saying in state it can't be applied to a float?

    • @McMurchie
      @McMurchie Před 7 lety

      Ok for anyone having this problem in the future - a quick refactor should resolve the issue. Its always a mystery what SKD does under the covers.

  • @proximacentauri3916
    @proximacentauri3916 Před 2 lety

    why do I'm unable to call java object like String from a class that extends AplicationAdapter class (FlappyDemo) ?

  • @sabashahrukh5448
    @sabashahrukh5448 Před 8 lety +4

    Hi Brent, in the update() and render() of the GameStateManager class,
    the lines states.peek().update(dt); and states.peek().render(sb); have update() and render() highlighted asking to create these two abstract methods.
    Please help !!

    • @bbauer04
      @bbauer04 Před 8 lety

      ever figure this out?? having the same problem!

    • @ragingcow
      @ragingcow Před 8 lety

      uncommenting didint help
      it says everything is unused

    • @JackyYe_TinyMC
      @JackyYe_TinyMC Před 7 lety

      try rebuilding your project?

  • @sunnylee6411
    @sunnylee6411 Před 8 lety

    why not extend screen? why use stack?

  • @subhadeeproy6147
    @subhadeeproy6147 Před 8 lety

    when i go on to run the application, it says "unfortunately application has stopped". what should i do??.

  • @LethalyGuy
    @LethalyGuy Před 8 lety

    Why isn`t the GameStateManager static on the State class?

    • @LethalyGuy
      @LethalyGuy Před 8 lety

      +Brent Aureli Thanks for the fast answer! I'm loving your videos so far. I finished watching the Flappy Bird ones and I'm now watching the Super Mario ones. Great job on them btw =P

  • @bramwellsimpson9835
    @bramwellsimpson9835 Před 7 lety

    Help! Android studio says that "Gradle: Error: Cannot find symbol class State" and "Gradle: Error: Cannot find symbol class GameStateManager" and "Cannot resolve symbol 'States'". Has anyone else come across this problem and how did they fix it? Edit: I deleted my old GameStateManager.java class and rewrote it still getting errors

  • @SilasMcfarlaneJustNumbers

    Hey guys, what is the point of the pop, set , and push methods?

    • @th14674
      @th14674 Před 7 lety

      When you're playing the game and pause it, the game PUSH a new screen on top of the game. When you unpause it, the game POP the new screen on top and get back to the game screen. That's what the Push and Pop method do. Meanwhile, the Set method is used to set a new value to a variable that's "private" in it's class. The reason you mark something as private and then use a Set method is to keep it away from hackers and increase the code's security.

  • @Kunait.
    @Kunait. Před 8 lety

    Hey Brent,
    I have an error and I can't fix it.
    We have gsm.render(batch);
    which calls the method render which takes a SpriteBatch as parameter.
    But it doesn't accept my SpriteBatch as parameter and I dont know why :(

    • @Kunait.
      @Kunait. Před 8 lety +1

      +RocketlauncherLP Ok I have fixed it already. Forgot to import SpriteBatch xD

  • @Thegamer-yp7qq
    @Thegamer-yp7qq Před 8 lety +5

    I didn't understand any thing

  • @joshpj5581
    @joshpj5581 Před 9 lety

    Good Video, but zoom in your camera dude

  • @pedrihub2658
    @pedrihub2658 Před 7 lety

    hi,
    why "states.peek().update(dt);" gives me error: Cannot resolve method 'update(float)'

    • @pedrihub2658
      @pedrihub2658 Před 7 lety +1

      Ok i removed Comments slashs from the file state.java and it's ok now, did i do the right sollution ??

    • @McMurchie
      @McMurchie Před 7 lety

      I have the same problem... not sure what it is

    • @pedrihub2658
      @pedrihub2658 Před 7 lety

      remove Comment slashs from the file state.java

    • @McMurchie
      @McMurchie Před 7 lety

      I did that - no such luck :(

  • @archangeltactics3802
    @archangeltactics3802 Před 4 lety

    render part aint working out for me

  • @thekiller0721
    @thekiller0721 Před 8 lety

    I cand use getDeltaTime why?

  • @davep7176
    @davep7176 Před 7 lety

    what kind of person puts a dislike button to this??

  • @chaoSefat
    @chaoSefat Před 8 lety

    Everything gives errors :(

  • @low--key
    @low--key Před 8 lety +8

    No disrespect, but I had to slow down your videos because you're a fast typer and talker.

  • @ragingcow
    @ragingcow Před 8 lety +1

    i wasted my time on this series getting errors on files i didn't even touch.

    • @Jacosaur
      @Jacosaur Před 7 lety +2

      it's because you probably had a typo