Menus - Pygame Tutorial

Поділитися
Вставка
  • Опубліковано 30 вер 2024
  • Menus (or different "screens") are something I get a lot of questions about. Menus are actually pretty simple to implement once you understand the basic concept behind them.
    The script:
    pastebin.com/X...
    Discord:
    / discord
    Twitter:
    / dafluffypotato
    This video and the code produced in it are released under: CC0 1.0 Universal (CC0 1.0). This puts the video and code produced in it in the public domain, so use it for whatever you want.
    #pygame #gamedevelopment

КОМЕНТАРІ • 161

  • @Simon-ik1kb
    @Simon-ik1kb 4 роки тому +161

    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 👍👌

    • @chadasonmcgraw8097
      @chadasonmcgraw8097 2 роки тому +3

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

  • @zackydev
    @zackydev 4 роки тому +74

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

  • @RobinNeville
    @RobinNeville 4 роки тому +60

    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 роки тому +25

    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 2 роки тому +3

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

  • @hugolml6538
    @hugolml6538 3 роки тому +6

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

  • @discotrain173
    @discotrain173 2 роки тому +2

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

  • @moonis_iqbal
    @moonis_iqbal 3 роки тому +5

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

    • @LeQuietkid
      @LeQuietkid 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 роки тому

      @@LeQuietkid what

  • @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!

  • @marcellomarianetti1770
    @marcellomarianetti1770 2 роки тому +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 роки тому +1

      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)

  • @b.manisha8291
    @b.manisha8291 2 роки тому +2

    Hey how can i add text on button for this code

  • @luneye206
    @luneye206 4 роки тому +4

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

    • @DaFluffyPotato
      @DaFluffyPotato  4 роки тому +3

      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 :)

  • @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.

  • @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

  • @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?

  • @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 роки тому +5

      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

  • @kefrov
    @kefrov 3 роки тому +3

    This helped me so much, thanks man.

  • @cardinel7918
    @cardinel7918 4 роки тому +3

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

  • @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)

  • @theseangle
    @theseangle 3 місяці тому

    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

  • @dubpper98
    @dubpper98 2 роки тому +1

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

  • @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

  • @GreenScreenKid284
    @GreenScreenKid284 2 роки тому +1

    Ooooooppppp

  • @armaanveersinghsidhu
    @armaanveersinghsidhu Місяць тому

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

  • @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

  • @spacegoat8559
    @spacegoat8559 4 роки тому +2

    I guess .collide_point() is a thing lol

  • @srqubit9480
    @srqubit9480 Рік тому

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

  • @RealBuzzerHours
    @RealBuzzerHours 2 роки тому +1

    I somehow understand this now, so thanks a lot!

  • @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?

  • @rgblogic448
    @rgblogic448 3 роки тому +1

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

  • @fabihoerlnein8774
    @fabihoerlnein8774 3 роки тому +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

  • @mikederino1412
    @mikederino1412 3 роки тому +1

    thank you for making it simple

  • @AppyTheApe
    @AppyTheApe 3 роки тому +1

    Can these codes be used in godot?

  • @programmingonly6538
    @programmingonly6538 3 роки тому

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

  • @canadianjoker9124
    @canadianjoker9124 2 роки тому

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

  • @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.

  • @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.

  • @veiga757
    @veiga757 3 роки тому +1

    Thanks a lot. Very helpful!

  • @thequicklyid5699
    @thequicklyid5699 Рік тому +1

    Very well made video!

  • @simplepycodes
    @simplepycodes 4 роки тому +2

    Impressive work.

  • @bornamusulin2557
    @bornamusulin2557 3 роки тому +1

    help my boy lubina he have 2 hours or dead

  • @cliffordwilliam3714
    @cliffordwilliam3714 3 роки тому

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

  • @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

  • @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 😅

  • @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.

  • @SchwiftyFingers
    @SchwiftyFingers Рік тому

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

  • @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 ?

  • @madankrishnan633
    @madankrishnan633 Рік тому

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

  • @ayushmoghe5767
    @ayushmoghe5767 2 роки тому

    Thank you for this, wishing you best of luck

  • @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

  • @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

  • @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?

  • @одинитолько
    @одинитолько 3 роки тому

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

  • @itsME-dc4vm
    @itsME-dc4vm 3 роки тому +1

    Nice ;D

  • @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)

  • @miffycomes5881
    @miffycomes5881 3 роки тому

    is there a command for start like for exit its exit

  • @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

  • @philtoa334
    @philtoa334 Рік тому

    Nice.

  • @johnstarfire
    @johnstarfire 4 роки тому +1

    Thanks, great explanation

  • @hirossxD
    @hirossxD 3 роки тому

    And how to do it in Pygame Zero ?

  • @LiquidLogic1
    @LiquidLogic1 Рік тому

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

  • @yardable1
    @yardable1 4 роки тому +1

    genuinely awesome !

  • @grimreaper7648
    @grimreaper7648 Рік тому

    noob

  • @manyk6971
    @manyk6971 3 місяці тому

    3:14

  • @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.

  • @FPLogistic
    @FPLogistic 3 роки тому

    THANK YOU SO MUICH DUDE

  • @alihadji9022
    @alihadji9022 2 роки тому

    how did you animate them?

  • @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.

  • @fdevstudio5692
    @fdevstudio5692 3 роки тому

    Hi, you work as what?

  • @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.

  • @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

  • @ayoubdkhissi
    @ayoubdkhissi 3 роки тому

    Thanks man you helped me alot

  • @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.

  • @francisvincejaca4077
    @francisvincejaca4077 2 роки тому

    how do u add images?

  • @keerthipranavi
    @keerthipranavi 3 роки тому

    this code helped us so much!! Thank you

  • @eggmeister6641
    @eggmeister6641 3 роки тому

    but the stack tho...

  • @gecriser
    @gecriser 3 роки тому

    Thank you so much

  • @emtydoctrine
    @emtydoctrine 3 роки тому

    Great video that explains using different screens perfectly!

  • @playonandroid9977
    @playonandroid9977 4 роки тому

    thanks a lot dude, you're awesome

  • @noah_edwrds
    @noah_edwrds 3 роки тому

    HAPPY BIRTHDAY !

  • @vialomur__vialomur5682
    @vialomur__vialomur5682 3 роки тому

    Thank you!

  • @pain.wav_06
    @pain.wav_06 4 роки тому +2

    your voice feels like a mixer-grinder

  • @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.)

  • @edux73
    @edux73 3 роки тому

    THANKSSSS!!

  • @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.

  • @wandinho1111
    @wandinho1111 4 роки тому

    Thank you!

  • @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

  • @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!!