Part 3: Game State Manager - Make Video Games w/ LibGDX: Flappy Bird
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
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
Thank you
Thanks a lot, you saved me another two hours of my evening lost on this problem haha
What should I do in class Menustate?
I still don't know what I'm doing but I feel like a pro
***** Yeah definitely I'll keep on this
+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.
You have made the stack staff effortlessly easy to understand. Thank you very much
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!
Very good tutorial. Easy to understand and presentation is done very nice.
Thanks for sharing your knowledge!
That's a nice clean code. Love it!
Oh my god your mechanical keyboard is making me very satisfied. I hear some blues :), what keyboard do you have?
Thanks is rly good tutorial ;)
Thank you so much !!!
How much learning time from scratch did it take you to become able to create games like this?
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?
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.
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?
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.
***** Thanks for your answer and the resources, very helpful! Would be great if you cover this concept in a future tutorial. :)
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.
Does the Render process run on the "main" JVM thread or is an alternate thread spawned when the game boots??
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?
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);
Which design pattern is this ? i mean for GameStateMachine..
ty for videos btw.
At 3:32 , { states.peek().update(dt) } , is the update(dt) the method inside the State.java file?
What difference would it make if I use Intents instead of a State Stack? Will That work?
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.
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??
Did you remember to uncomment everything from the State class?
Oh this is why my program was importing some State library. Called mine States instead of State. Thx for the help man =D
Yeeeeah, thank you
Who gets an error on Sack - use Stack or private java.util.Stack states;
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.
This should all make sense in the end, right?
my State dont work every time i do the thing i gives me options to import stuff and if i do i get errors
If glClear erase everything on screen then why not remove completely glClearColor? Is there a reason to keep it?
How would I use a fixed timestep instead of getDeltaTime?
could u please explain why we have to update delta time ? ELI5 please
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
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?
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.
why do I'm unable to call java object like String from a class that extends AplicationAdapter class (FlappyDemo) ?
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 !!
ever figure this out?? having the same problem!
uncommenting didint help
it says everything is unused
try rebuilding your project?
why not extend screen? why use stack?
when i go on to run the application, it says "unfortunately application has stopped". what should i do??.
Why isn`t the GameStateManager static on the State class?
+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
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
Hey guys, what is the point of the pop, set , and push methods?
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.
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 :(
+RocketlauncherLP Ok I have fixed it already. Forgot to import SpriteBatch xD
I didn't understand any thing
Good Video, but zoom in your camera dude
hi,
why "states.peek().update(dt);" gives me error: Cannot resolve method 'update(float)'
Ok i removed Comments slashs from the file state.java and it's ok now, did i do the right sollution ??
I have the same problem... not sure what it is
remove Comment slashs from the file state.java
I did that - no such luck :(
render part aint working out for me
I cand use getDeltaTime why?
what kind of person puts a dislike button to this??
Everything gives errors :(
No disrespect, but I had to slow down your videos because you're a fast typer and talker.
im watching a 1.5x speed
i wasted my time on this series getting errors on files i didn't even touch.
it's because you probably had a typo