Menus - Pygame Tutorial

Поделиться
HTML-код
  • Опубликовано: 24 дек 2024

Комментарии • 162

  • @RobinNeville
    @RobinNeville 4 года назад +63

    You legend. Giving each screen its own game loop is such a good idea.

    • @GeneralPet
      @GeneralPet 3 года назад +7

      I was wondering how I can encapsulate each screen and it's contents but never thought of separate game loops. What a legend

    • @RobinNeville
      @RobinNeville 2 года назад +3

      In hindsight (and having implementing the idea) I retract this comment. Each loop requires the same boilerplate setup (clock, event handling, etc).

    • @nicolaiv.9757
      @nicolaiv.9757 2 года назад

      @@RobinNeville What do you recommend then?

    • @dylanboyd6147
      @dylanboyd6147 Год назад +2

      @@nicolaiv.9757 using a gamestate stack

    • @chrisogb11
      @chrisogb11 Год назад

      @@dylanboyd6147 how would you go about doing that?

  • @Garfield91076
    @Garfield91076 4 года назад +26

    Actually figured this out on my own surprisingly. Saw this vid and wanted to compare our code, turns out its pretty similar! Thanks for the videos!

    • @darealsooski
      @darealsooski 3 года назад +3

      it's more that people coming to these tutorials are new to coding (like me lmao) so it feels very smart and impressive

  • @zackydev
    @zackydev 4 года назад +74

    yes YES this is what i was thinking and this video immediately popped up youtube algorithm is good

  • @Simon-ik1kb
    @Simon-ik1kb 4 года назад +162

    would love to see a full series on how to make RPG game. Like basic mechanics, systems.

    • @disdis6127
      @disdis6127 3 года назад +12

      Yeah I also requested hi several times may be he is gonna do so in 2021 who knows?

    • @berightback854
      @berightback854 3 года назад +5

      Ye that would be great

    • @soupnoodles
      @soupnoodles 3 года назад +14

      The thing is, theres no point in watching tutorials when you have the fundamentals down. Doing so only makes you overly dependant on them and unable to do any real project by yourself without copying code from the same source you used to make the tutorial's game.
      Ive been through this, and trust me, i definetly recommend you dont watch tutorials for full games, even for tutorials like these whats important is to take away the idea of how someone else goes about doing it, but you cant really just do it the exact same way.
      A program is essentially the visual form of someones logic. You cant think the same way as somebody, so it makes sense that when your making a full game, you only use the same *ideas*, but not the same logic.
      For example putting your particles in a list with list comprehension or the idea of making the tilemap as a matrix. But when your implementing those, they need to be from solid effort, reading docs and articles
      Otherwise, your really never gonna be able to make your own game :)

    • @iliyarh
      @iliyarh 3 года назад

      @@soupnoodles facts 👍👌

    • @chadasonmcgraw
      @chadasonmcgraw 3 года назад +3

      I would say learning C++ would be the best for learning an RPG...

  • @armaanveersinghsidhu
    @armaanveersinghsidhu 4 месяца назад +1

    dude this is genius. i have been bashing my head over this stupid problem for so long.

  • @fabihoerlnein8774
    @fabihoerlnein8774 4 года назад +1

    I have never used the commend section before, but today I got so much core input in 3 min... nice video and thank you

  • @Amb3rjack
    @Amb3rjack 2 года назад +1

    I thought this vid was fantastic. I'm trying to get into the whole programming language thing almost from scratch. I've done a couple of really good python tutorials on line so I can get the gist of what's going on here. But this is many levels on from my current ability and it is truly inspiring and exciting to watch.
    An amazing vid in my opinion. Thank you so much for posting.

  • @hugolml6538
    @hugolml6538 3 года назад +6

    You are a real benediction for us the beginners ! Thanks a lot !

  • @discotrain173
    @discotrain173 2 года назад +3

    How do you code the menus such that you maneuver through them with arrow keys rather than clicking the buttons with your mouse?

  • @rgblogic448
    @rgblogic448 3 года назад +1

    Watched tons of videos an didn't quite understand until watching your video! Great work!

  • @b.manisha8291
    @b.manisha8291 2 года назад +2

    Hey how can i add text on button for this code

  • @gautamsharma9897
    @gautamsharma9897 4 года назад +4

    Hey, Want to know how did add that animation at 6:02.
    And could you also make a video on how to implement the card video that you have shown at 6:42

    • @dafluffypotatovr7362
      @dafluffypotatovr7362 4 года назад +4

      The movement in that animation is done by having a target and moving x% towards the target every frame so it slows down as it gets closer. The card menu works similarly.

    • @gautamsharma9897
      @gautamsharma9897 4 года назад

      @@dafluffypotatovr7362 Thanks for reply

    • @moonis_iqbal
      @moonis_iqbal 3 года назад +1

      And how to add a target... Please make a video on card menu tutorial for beginner

  • @theseangle
    @theseangle 6 месяцев назад

    I recommend checking out State Design Pattern or more broadly Finite State Machines in the context of game development to solve this exact problem, after you understand what the author of the video is proposing

  • @mindoasis.meditation
    @mindoasis.meditation 2 года назад +1

    Hello very important question, I have a project due and I'd like to know how to add text to these button?

  • @LiquidLogic1
    @LiquidLogic1 Год назад

    This is a fantastic tutorial - very easy to follow and understand. Thank you!

  • @external111
    @external111 4 года назад +3

    at 6:18 there is a button to go fullscreen, what is the code to make your Pygame window fullscreen?

    • @DaFluffyPotato
      @DaFluffyPotato  4 года назад +7

      Use the pygame.FULLSCREEN flag when you use .set_mode

  • @Katulo14
    @Katulo14 3 года назад

    some bug that occurs in linux, the options don't work and the button doesn't appear and the escape also doesn't work

  • @ayushmoghe5767
    @ayushmoghe5767 2 года назад

    Thank you for this, wishing you best of luck

  • @srqubit9480
    @srqubit9480 Год назад

    Pls You can teach how to make a resolution selector and that absolutely everything adapts to the new resolution

  • @SchwiftyFingers
    @SchwiftyFingers Год назад

    You are amazing. ❤ Even Chat gpt doesn't make it this simple

  • @madankrishnan633
    @madankrishnan633 Год назад

    how would you implement this same main menu like code for an in-game pause menu?

  • @luneye206
    @luneye206 4 года назад +4

    How do you implement the transitions between windows such as 6:10 ? Thanks in advance :)

    • @DaFluffyPotato
      @DaFluffyPotato  4 года назад +4

      Just blit a black surface over everything at an increasing opacity. (and do the reverse afterwards) I'll probably make a video on it.

    • @luneye206
      @luneye206 4 года назад +1

      @@DaFluffyPotato that would be awesome! i was thinking same but ignore how to increase or decrease the opacity of an object over time, thanks for your answer :)

  • @SchwiftyFingers
    @SchwiftyFingers Год назад

    Where can i see the code for the menu screen shown for drawn down abyss?
    I wonder if the Draw_text function contain the code for creating the buttons around the text and centering it perfectly 😅

  • @angelluisgarciaguzman5598
    @angelluisgarciaguzman5598 4 года назад +2

    This is the part where you clutch that sweet-sweet inheritance quirk

  • @tristandombroski9677
    @tristandombroski9677 Год назад

    I wish I could like this video twice.

  • @moonis_iqbal
    @moonis_iqbal 3 года назад +5

    I liked the card menu most...!!
    May you explain please, how it is created in pygame ?

    • @JBP.Shr3k
      @JBP.Shr3k 2 года назад

      If it was created with Python, then it should be the same as PyGame (I haven't watched the video so I don't know whether it's in Python or not)

    • @kunns123
      @kunns123 2 года назад

      @@JBP.Shr3k what

  • @aliza4980
    @aliza4980 2 года назад

    Hi, iv copied the code but I keep getting an invalid syntax on the mx .. does anyone know how to fix that?

  • @kefrov
    @kefrov 3 года назад +3

    This helped me so much, thanks man.

  • @canadianjoker9124
    @canadianjoker9124 3 года назад

    How can i do this with classes, i have 2 games in its own classes, and a main loop. ,

  • @marcellomarianetti1770
    @marcellomarianetti1770 3 года назад +3

    quick question: if I implement a pause menu, like this one, when I resume the game I guess the game loop gets re-initialised, so the game starts again from the beginning. Is there a way to avoid that?
    I was thinking maybe you have to somehow save the game state somewhere and when 'resume' is clicked you load the game from that position

    • @blackgameneon
      @blackgameneon 2 года назад +2

      I am also learning Pygame.
      I just took another tut, and used this:
      pygame.time.delay(5000)
      It delays the game (the clock?) for 5 seconds, then resumes the game.
      So you might need to use a flag(?) that will tell the function when the resume button is pressed.
      pygame.time.delay(ResumeButtonReleased)

  • @RealBuzzerHours
    @RealBuzzerHours 3 года назад +1

    I somehow understand this now, so thanks a lot!

  • @emtydoctrine
    @emtydoctrine 3 года назад

    Great video that explains using different screens perfectly!

  • @cliffordwilliam3714
    @cliffordwilliam3714 3 года назад

    Would it be better to use state machine to make the menus?

  • @dubpper98
    @dubpper98 2 года назад +1

    wow men! thanks a lot, very nice tutorial and very nice menus! :O

  • @dinistavares7263
    @dinistavares7263 3 года назад

    Hello I have copied the code and changed some colours and sizes, but I don't know how to put a text in the buttons, can someone tell me how to do it ?

  • @tristancummings5925
    @tristancummings5925 3 года назад +1

    Question...how do you make the code play a pre-made game when you press a button? I've been trying to figure that out for a while?

    • @wowgodz-5349
      @wowgodz-5349 3 года назад

      paste the code into the loop is faster

  • @thequicklyid5699
    @thequicklyid5699 2 года назад +1

    Very well made video!

  • @sabununicorn132
    @sabununicorn132 2 года назад

    Hi, how do you put a text inside the rectangle ? I don't quite understand it

    • @discotrain173
      @discotrain173 2 года назад

      When you draw the red rectangle, you just blit text after drawing the red rectangle

  • @2MSTennis
    @2MSTennis Год назад

    In game menu like an inventory! Would you just blit a screen on an if statement? I get it to appear but disappears quickly after! (In game loop)

  • @sevcandincel
    @sevcandincel 4 года назад +4

    I think calling font.render every frame is a bad idea. Also i dont like pygame's bad font rendering. But what you are doing with that library is awesome!

  • @AppyTheApe
    @AppyTheApe 3 года назад +1

    Can these codes be used in godot?

  • @2MSTennis
    @2MSTennis Год назад

    Need more of this! If you could and have the time I’d like to see how you make a fully developed menu.

  • @noah_edwrds
    @noah_edwrds 3 года назад

    HAPPY BIRTHDAY !

  • @simplepycodes
    @simplepycodes 4 года назад +2

    Impressive work.

  • @yardable1
    @yardable1 4 года назад +1

    genuinely awesome !

  • @mikederino1412
    @mikederino1412 3 года назад +1

    thank you for making it simple

  • @DeeMasta
    @DeeMasta 3 года назад +1

    I was testing and running before the whole thing finished and I was getting weird errors about syntax for "button_2 = pygame etc...
    More specifically the "b" in button was highlighted, but it had no problem with button_1 = py..etc
    I checked all my other syntax and I couldn't find a reason but I copied the pastebin and it was the exact same, no issues! lol. Thanks! This helped me grasp the refreshing of the screens while switching functions/menus/screens.

  • @cardinel7918
    @cardinel7918 4 года назад +3

    Nice Video!
    A great explanation, easy and with no missunderstandings, such video I looked for.
    thanks man!

  • @keerthipranavi
    @keerthipranavi 3 года назад

    this code helped us so much!! Thank you

  • @khalvissi9303
    @khalvissi9303 4 года назад +3

    Hello ! First, thanks for your video ! your explanations are very cool.
    I have an issue with mine, I have two methods, the first one makes you go to the second by a click (exactly like your tutorial) but, in the second one, i have 3 buttons , but they don't work, the error is :
    UnboundLocalError: local variable 'click' referenced before assignment
    I believed this was due to the fact that I allready used "click" in the first method, but no, if i change the name, this still not working, any idea ?

    • @DaFluffyPotato
      @DaFluffyPotato  4 года назад +1

      Python variables are local by default. Pass the click variable to the function giving you the error.

    • @khalvissi9303
      @khalvissi9303 4 года назад

      @@DaFluffyPotato oh ok thank you !

    • @darien9834
      @darien9834 2 года назад

      Hey, I am having the exact same problem and i have no idea how to fix it and it only happens randomly as well , can you please help me

    • @khalvissi9303
      @khalvissi9303 2 года назад

      @@darien9834 Hey, could you send me your functions, I'll check that

    • @darien9834
      @darien9834 2 года назад +1

      @@khalvissi9303 i messed around for a bit and it just stopped happening now but thanks for the reply

  • @miffycomes5881
    @miffycomes5881 4 года назад

    is there a command for start like for exit its exit

  • @francisvincejaca4077
    @francisvincejaca4077 2 года назад

    how do u add images?

  • @doviledasilvamonteiro8439
    @doviledasilvamonteiro8439 4 года назад

    When i click to open the game. it just flicks the game()
    like it opens game() , but automatically runs main_menu()
    since its there at the bottom, i guess...
    how to do it.... ? i think i done everything the way u showed....
    def main menu ( choose game() )
    , then def game
    then main_menu() at the end. ...

    • @DaFluffyPotato
      @DaFluffyPotato  4 года назад

      I don’t remember what I did in this video very well, but if your results don’t match mine, try the code in the description.

  • @jacobjrgensen4828
    @jacobjrgensen4828 3 года назад

    Thanks, just what i was looking for. But was woundering wouldt it be smarter making a class instead of copying det functions everytime. Just to make it look a bit cleaner

  • @hirossxD
    @hirossxD 3 года назад

    And how to do it in Pygame Zero ?

  • @alihadji9022
    @alihadji9022 2 года назад

    how did you animate them?

  • @victoraugusto313
    @victoraugusto313 4 года назад +1

    hello, how did you put the background image on the menu?

    • @DaFluffyPotato
      @DaFluffyPotato  4 года назад +1

      You can put something in the back by rendering everything on top

    • @victoraugusto313
      @victoraugusto313 4 года назад

      @@DaFluffyPotato ok ok

    • @victoraugusto313
      @victoraugusto313 4 года назад +1

      @@DaFluffyPotato How to put a button so that when I press on options I can go back to the menu?

  • @josemiguelgomesteixeira9274
    @josemiguelgomesteixeira9274 3 года назад

    Won't there be any issues by recurrently calling one function inside another? What if the player goes from the game to the main menu repeatedly?

    • @DaFluffyPotato
      @DaFluffyPotato  3 года назад

      You return from the game instead of calling the menu again so that it just goes back up to the menu.

  • @Foon2Death
    @Foon2Death 4 года назад +4

    No questions, just want to say I enjoyed the info and examples man. Thanks from someone using pygame and eyetracking for his thesis

  • @johnstarfire
    @johnstarfire 4 года назад +1

    Thanks, great explanation

  • @veiga757
    @veiga757 4 года назад +1

    Thanks a lot. Very helpful!

  • @Steppy
    @Steppy 4 года назад

    how do i make it so when i click on the game button it switches to the actual game?

    • @DaFluffyPotato
      @DaFluffyPotato  4 года назад

      if click and mouse_r.colliderect(button_r):
      run_game()

    • @Steppy
      @Steppy 4 года назад

      @@DaFluffyPotato thanks! but i also found another way
      def game():
      running = True
      while running:
      screen.fill((0,0,0))

      draw_text('Game', font, (255, 255, 255), screen, 20, 20)
      for event in pygame.event.get():
      if event.type == QUIT:
      pygame.quit()
      sys.exit()
      if event.type == KEYDOWN:
      if event.key == K_ESCAPE:
      running = False

      pygame.display.update(main())
      mainClock.tick(60)
      i added (main()) to the display update at the bottom

    • @Steppy
      @Steppy 4 года назад

      @@DaFluffyPotato i also have another question. im trying to text on the button but i dont know how to do it. (i have also seen the comment that asks this aswell but i dont understand how to do it)

    • @DaFluffyPotato
      @DaFluffyPotato  4 года назад

      @@Steppy Pygame doesn't have built in functionality for "buttons". You make them yourself out of images, text, and input. (Show text on top of an image, check for clicks, then check if the click is on the button.)

  • @kelsierii4747
    @kelsierii4747 3 года назад

    hi, I know there are a hundred of comments here and you probably get dozens a day, but I followed your advice on this and really wanted to know, do you know a way of displaying a variable such as coins or gold on the menu, while that variable is defined and changed in one of the game loops. Id be really thankful for any help you could give me.

  • @joshua_leyer
    @joshua_leyer 4 года назад

    Hello, I am studying pygame recently. I come from China. There are few domestic materials. Most of them are talking about the APIs given by pygame. A few very simple cases. I still don't know what to do next. It feels like there is no game programming thought. When I want to see some other people's game cases on the official website, I don't understand what others have written. Most of them have no comments. what should I do?

    • @DaFluffyPotato
      @DaFluffyPotato  4 года назад

      I learned by messing around with people’s code to see what happened. This can still be done without comments. If you know the basics, I’d recommend just making simple stuff and trying to figure out the complex stuff. A lot of stuff isn’t actually Pygame specific. The concepts apply to just about any graphics library.

  • @GeikoTreyarch
    @GeikoTreyarch 2 месяца назад

    Damn if only i learned this months ago before i added SOOO MUCH MENUS to my game -.-
    Refactoring will take awhile but definitely will need to be done aince this causes less bugs

  • @suspensed_
    @suspensed_ 4 года назад

    how did you make the rounded buttons?

    • @DaFluffyPotato
      @DaFluffyPotato  4 года назад

      Those are images.

    • @suspensed_
      @suspensed_ 4 года назад

      @@DaFluffyPotato can you tell me how you did it please?

    • @suspensed_
      @suspensed_ 4 года назад

      @@DaFluffyPotato and how to adapt to different screen resolutions? I just have a problem. I am making a game with a resolution of full hd and the monitors with a lower resolution have buttons moving

    • @moonis_iqbal
      @moonis_iqbal 3 года назад

      I didn't find any good tutorial on round buttons in pygame so in my game I applied pygame rectangular shapes with border radius property.... Simple !

    • @moonis_iqbal
      @moonis_iqbal 3 года назад

      @@DaFluffyPotato plz explain how to create clickable image buttons!!

  • @coconaatti2878
    @coconaatti2878 4 года назад

    hi, can anyone tell me what does DaFluffyPotato game dev use for making the menu?

    • @daiwikdhar6464
      @daiwikdhar6464 4 года назад

      He used python and imported pygame to make it... He didn't use a game dev.!! You can make this with any IDE for python!! Best of luck!

    • @coconaatti2878
      @coconaatti2878 4 года назад

      I mean I used pygame and python in pycharm and didn't work

    • @daiwikdhar6464
      @daiwikdhar6464 4 года назад

      @@coconaatti2878 You need to install pygame and then import it... Search for it on youtube..."How to install pygame and use it?"

    • @coconaatti2878
      @coconaatti2878 4 года назад

      Oh ok thanks so much 😊

    • @daiwikdhar6464
      @daiwikdhar6464 4 года назад

      @@coconaatti2878 Np

  • @ayoubdkhissi
    @ayoubdkhissi 3 года назад

    Thanks man you helped me alot

  • @playonandroid9977
    @playonandroid9977 4 года назад

    thanks a lot dude, you're awesome

  • @fdevstudio5692
    @fdevstudio5692 3 года назад

    Hi, you work as what?

  • @FPLogistic
    @FPLogistic 3 года назад

    THANK YOU SO MUICH DUDE

  • @raisulislam3593
    @raisulislam3593 4 года назад

    How can't understand your map source code
    Please explain how to design a map
    Please please please 🙏😢🙏😥

    • @projectvibe1226
      @projectvibe1226 4 года назад

      he have a video in his pygame beginner series

  • @itsME-dc4vm
    @itsME-dc4vm 4 года назад +1

    Nice ;D

  • @gecriser
    @gecriser 3 года назад

    Thank you so much

  • @yurii.okereshko
    @yurii.okereshko 4 года назад +2

    Finally found your channel). Really impessed with amount of work, good job, keep it going!
    P.S. Hello from Ukraine)

  • @voltifer5267
    @voltifer5267 4 года назад +3

    Hey, Can you make a levels tutorial?

    • @DaFluffyPotato
      @DaFluffyPotato  4 года назад +2

      That should be covered between the video where I implemented levels loaded from files and this video.

  • @philtoa334
    @philtoa334 Год назад

    Nice.

  • @wandinho1111
    @wandinho1111 4 года назад

    Thank you!

  • @spacegoat8559
    @spacegoat8559 4 года назад +2

    I guess .collide_point() is a thing lol

  • @edux73
    @edux73 4 года назад

    THANKSSSS!!

  • @GreenScreenKid284
    @GreenScreenKid284 2 года назад +1

    Ooooooppppp

  • @pain.wav_06
    @pain.wav_06 4 года назад +2

    your voice feels like a mixer-grinder

  • @eggmeister6641
    @eggmeister6641 3 года назад

    but the stack tho...

  • @manyk6971
    @manyk6971 6 месяцев назад

    3:14

  • @programmingonly6538
    @programmingonly6538 3 года назад

    You speak like a drunk (do not offend bro i am your biggest fan)

  • @bornamusulin2557
    @bornamusulin2557 3 года назад +1

    help my boy lubina he have 2 hours or dead

  • @одинитолько
    @одинитолько 3 года назад

    just let me steal the code... im too tired for this rn

  • @grimreaper7648
    @grimreaper7648 2 года назад

    noob

  • @vialomur__vialomur5682
    @vialomur__vialomur5682 3 года назад

    Thank you!