The First Game Done (UI) - How to Make a 2D Game in Java #10

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

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

  • @jamesconwell2767
    @jamesconwell2767 2 года назад +23

    Best java tutorial on youtube, you need more love.

  • @Mypremiumacct
    @Mypremiumacct 3 месяца назад +3

    I had to do a lot of debugging and not even chat gpt4o could detect my problem...turns out my background green I set in the very beginning caused the sound and text at the end to not appear and I finally figured it out after combing through it all. I feel like I am becoming more competent as to how to fix little funny mishaps like this and have been having a blast experimenting with other features such as a dodge roll(though I dont have sprites for it yet). I can feel how its starting to shape up. And in the end when you tried for a better score, that showed me, and I felt it too, that this is really becoming a game. I cannot wait to deviate further from your game to really make mine stand out but I will follow through till the end just to learn everything I can from you. Thank you so much and I cant wait to do more!

  • @DormantLemonGames
    @DormantLemonGames 2 года назад +51

    So glad you went through the effort of making this series! A really good introduction to 2d game development. Thank you so much for sharing!

    • @RyiSnow
      @RyiSnow  2 года назад +9

      It was my pleasure! It took longer than I thought but I'm glad I made it :D

  • @gustavhenriksson867
    @gustavhenriksson867 2 года назад +5

    Love how many hours was spent to make the first half when it took 30 sec to win the game :D
    Love coding and learning from you Ry! you are the very best!

  • @ihavenoidea2736
    @ihavenoidea2736 2 часа назад

    Damn. Completed the first half. Cannot wait to continue, and implement my own stuff as well. Thank you, RyiSnow, for your service❤

  • @snarpking
    @snarpking 2 года назад +5

    You are an actual god among men. Thank you for blessing us with your presence on RUclips.

  • @Phil1490
    @Phil1490 2 года назад +17

    Dude this series is SOOOOOO GOOD! You're a very good teacher. You explain things very well and appreciate these videos very much.

  • @ReivajGG55
    @ReivajGG55 6 месяцев назад +2

    You are a legend. Here i am. Learning how works a game in Java to Present and defend my Programming II Project. Thank you so much for the tutorials. I will keep Learning new things with you.

  • @RyiSnow
    @RyiSnow  2 года назад +71

    This is the final episode of the first half of this tutorial. Thanks for watching! I hope you enjoyed our journey so far.
    BUT this is not the end! After this, I will probably make a couple of extra video to answer and apply the requests/questions that I've received throughout this series. I also update the tile images to improve the graphics.
    Then we move onto the second half and change this to action RPG. If you're interested, please come along!

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

      Nice work , i think you have made a good job here,

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

      If I want to add a black panel behind the icons, then I have to add a JPanel, I suspect that is the easiest way.

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

      You can draw a rectangle :)

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

      @@RyiSnow thats was very good. Work fine :)

    • @abcd-pr6tw
      @abcd-pr6tw 2 года назад +1

      Hello, first thank you for your videos! when are you going to make the part 2?

  • @vVictorNos
    @vVictorNos 7 месяцев назад +1

    Made it to first half yes!!
    You have no ideaI how much i appreciate these tutorials, thank you so much! I will follow through the end!!

    • @RyiSnow
      @RyiSnow  7 месяцев назад

      Glad I could help! Hope you'll enjoy the rest of the series!

  • @sukkarakan_haitang
    @sukkarakan_haitang 2 года назад +13

    I don't know if you did a part where getting an object lets the character walk over solid objects, I just watched till this part 10. But I really wanted a walk on water object. So I added that on my own and IT WORKED. YOU DON'T KNOW HOW HAPPY BEING ABLE TO FIGURE OUT SOMETHING ON MY OWN MAKES ME HERE(probably do though). This series is amazing, honestly I love it to death, this is the only thing reassuring me, that I did not make a wrong decision by taking CSE as my undergrad major which I've been dreading for the past 7 months. And I won't be f-ing up my life thinking I shouldn't have chosen this just because I thought making games would be fun. IF I AM GUIDED PROPERLY IN THE EARLY STAGE I CAN, AND IN SHA ALLAH I'LL BE GREAT AT IT.
    DAKARA, WATASHI WA ANATA GA SHITE KURERU KOTO NI KOKOROKARA KANSHASHITE IMASU

    • @RyiSnow
      @RyiSnow  2 года назад +6

      I know that feeling. It feels great when you could figure things out and your own idea comes to fruition. The possibility is infinite and it makes programming so much fun. Great to hear that you experience that and I hope such a moment will keep coming to you. それとあなたの日本語はとても上手ですよ。 Good luck with your CSE study!

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

      honestly, making an object that lets you walk on water isn't exactly hard...

    • @goozjeesh46
      @goozjeesh46 Год назад +10

      @@Entity_The_Demon why you gotta put them down like that? they're probably new to programming and dont know how to do very many things. i also am very happy when i can figure things out on my own

    • @shopenggu4779
      @shopenggu4779 Год назад +1

      Hey, is it okay if I'd ask how you made this function?

    • @sukkarakan_haitang
      @sukkarakan_haitang Год назад +3

      @@shopenggu4779 Just add a case where if you get the shoes water tile changes to not an obstacle.

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

    This series is amazing. I’m so glad I put in the time for this one.

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

    I'm following your tutorial since 1 month, I started learning Java since 2 months and it's a very nice tutorial for practicing all I've learned. It's so playful !
    I'm not fluent in English but with english subtitles I can easily follow your explanations and understand what I'm doing haha.
    I can't thank you enough for all the work you have done.
    I will go to the end of this tutorial in honor of your work.
    Hope this will help me to be a junior developper after all.

  • @janrui2477
    @janrui2477 Год назад +1

    I actually finished the first half!! I learned so much from this, I still have to review other codes though... after that I'll be watching the next part!! see you there fellow watchers!

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

    good job, as the tuturial finish, a work game engine is done

  • @hameemhoque
    @hameemhoque Год назад +1

    Hi RyiSnow, not sure you'll read this but that's okay.
    I just wanna show my gratitude for this series. It's been super helpful and informative, and I've been able to understand you clearly as you explain things so well. I've also been making comments in the code to help me understand the code better and I've been taking notes on pen and paper.
    Seriously though, this series is incredible and I'm excited to go through the other 50 videos you have made. Thank you so much, RyiSnow! 😁 💯

    • @RyiSnow
      @RyiSnow  Год назад +1

      Thank you so much for your kind words! It means a lot to me. I hope you will keep enjoying the series!

  • @sorcerian_bootleg7112
    @sorcerian_bootleg7112 2 года назад +6

    Always cool to see a new video of this series!
    I am curious about some details that this game could need. For example, a menu, with an inventory. Or a menu to configure music and sound volume (or to mute them). Or to exit game.
    There's also more complex elements i'm curious about. One of them is the use save datas to store your progress. Or the use of flags to progress through the story...
    I suppose all of this is too complex and it would take a lot of time. But i hope you can go through some of this questions some day! :D

    • @RyiSnow
      @RyiSnow  2 года назад +9

      No worries, everything you just mentioned (menu, inventory, save/load) will be featured in the second half :P
      The first half was just meant for introducing the basics. It will be a completely different game when everything is done!

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

      @@RyiSnow that's cool! Looking forward to it!

  • @leonidas14775
    @leonidas14775 4 месяца назад

    Super! your tutorial makes learning Java fun

  • @AlexPerez-gk6np
    @AlexPerez-gk6np 8 месяцев назад

    You’re the best man. I can
    rarely sit through tutorials and follow along, but you made it interesting and fun!

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

    31:97 here !!! 😉😉😉 Thank you man for that little but fully game so far.^^ 👍👍👍
    The key controls needs diagonal movement, or should react more precise when releasing a key. For example: when you press W & D together and then you release W a millisecond, the player should walk right. Sometime you have to walk a little bit down for being able to walk again upwards.

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

    Really enjoyed the first part, I'm gonna reflect a bit on what I learned and start my own game before continuing but again and again and again: thank you so much!

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

    Thank you! I finally finished this version of the game! I took a little longer because I was incorporating the Jar file at the same time. (Thank you for those tutorial video as well!)

  • @nadinewalter-lang9333
    @nadinewalter-lang9333 4 месяца назад

    You're legend! Thank you very much for your effort!

  • @mikemazanetz4183
    @mikemazanetz4183 7 месяцев назад

    cool - you answered my question from tutorial #9 !

  • @silentdisposition
    @silentdisposition Год назад +1

    Just a quick tip when checking boolean variables in if statements instead of saying (if var == true) you can just use if(var) as this will automatically check if the boolean is true and if you want to check for false you use if(!var), slightly saves memory and looks better :)

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

    Ryi sos mejor que mis profesores de la universidad!!!

  • @hentercato
    @hentercato 9 месяцев назад +1

    You are my hero!!!🥰

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

    ryi, you are the best! 👍

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

    Love this series very much!!! Many thanks for your effort

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

    Your message timer was very useful. I included a bump sound effect when player collides with a wall. Collision happens too rapidly and it sounds horrible though. So the timer solves 2 problems.

  • @luckyyunque1231
    @luckyyunque1231 8 месяцев назад

    I made it this far!

    • @RyiSnow
      @RyiSnow  8 месяцев назад

      Congratz!

  • @midostar3463
    @midostar3463 Год назад +3

    Ryi Hello!
    Thanks for this good tutorial. It helped me to improve myselft and to familiarize with games structure, especially in Java :D
    I have only one question and will be happy if you answer it.
    How do you create executeble JAR projects, so it works after you double click with mouse on it?
    I'm working in intellij idea and there's possibility to press File -> Project Structure -> Artifacts -> Jar from Modules and choose main class.
    After doing that, you press build ->build artifact and intellij creates JAR in out ->artifacts.
    The problem is that this JAR isn't executable for usual person (it can be run only in intellij). I tried to run it on my PC by double clicking in the windows explorer, but it hasn't reacted. The packet structure is the same as yours (actually it wasn't the same, but for a test i did it the same as in video).
    I search whole internet, but still haven't found any solution. Maybe there's another way to create the executable JAR? (I also tried console commands, but it hasn't succsead as well).
    I'm looking forward to your reaply and thanks in advance!!

  • @NikitaBomba112
    @NikitaBomba112 Год назад +1

    Thanks you so much for this video!

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

    Much fun to code this game. Thanks a loy

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

    thank you for the helpful information :)

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

    Thanks man this really helps !

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

    Great work, thx!

  • @deborahlawani5539
    @deborahlawani5539 15 дней назад

    Nice work @ryisnow, but is there a way i can implement the current distance of the player away from its initial location. with x and y axis

  • @boltgreywing4562
    @boltgreywing4562 10 месяцев назад

    I am kind of curious if it is possible to build your own Font class so you don't have to worry the built in text font so that it calls from the graphics that you put in and scales or decreases them accordingly? I haven't really seen many videos out there that tackle that sort of challenge.

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

    It might only be in my laptop, I dont know but
    when I press both up and down the char goes down
    if up + down goes up and down after i press down
    if down + up goes down
    Same with right and left
    if left + right goes left and right after i press right
    if right + left goes right
    Also i just realized the character could move diagonally before if i pressed left/right + up/down
    but now the character dont move that way

  • @mohamedzouad498
    @mohamedzouad498 9 месяцев назад

    I like this guy

  • @Dogukan-tm5xh
    @Dogukan-tm5xh Год назад

    53,37 pff :D sdada ver nice teacher :)

  • @Often_Guy
    @Often_Guy Год назад +1

    0:56 That's weird because I clearly hear both sounds at the same time

  • @AlexanderHL1919
    @AlexanderHL1919 5 месяцев назад

    *edit* I placed the gp.playSE(3) before the if loop in the door case in the Player class hence why it was playing the sound when detecting collision with the player. And it sounded weird because it was playing it hundreds of times over itself I guess for as long as there was collision detected with the player against the door.
    Hi RyiSnow, thank you for making this series. Its really helpful. If I may ask, when I run up to a door like you do at 18:11, and I do not have a key for the door yet, the game still plays a sound effect, not the unlock one, just a very strange sound. It sounds like a bug, but I'm not sure how to fix it. Have you run into this issue?

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

    Please give source code for the first game🥺🥺🥺🥺🥺🥺

  • @davidbijaksantoso-085
    @davidbijaksantoso-085 Год назад +1

    hey I have a problem, is there a way to completely stop the game when character reach the treasure? thank you.

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

    I’m really enjoying this series. I’ve tried following similar tutorials on RUclips, but they tend not to explain enough and don’t put concepts together in a easy to follow progression like this. Thank you for all the work you put into this!
    If I may ask, is there a way to convert the playtime counter display into a more standard time format (hh:mm:ss)? I’ve been searching online to try and figure it out (the decimal point looks a little weird to me), but I’be been unable to find a way to do it with a double.

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

      You can do that by creating 3 variables (hour, minute, and second) When the second hits 60, set 0 to the second and add 1 to the minute, and do the same for the hour variable too.

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

      @@RyiSnow Ah, yes, I didn't think of that. Thank you!

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

    hello i would like to say your tutorials are really helpful for me for my school project !! tysmm for that ! however i would like to ask for the play time how do you make it decrease and stop at 0? as i manage to make it countdown from a set timing but not sure how to stop the time when it reaches 0

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

      You can create an if statement and stop decreasing the time after it hit 0.

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

    Nice!

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

    Thank you !

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

    hello! I have a few questions.
    is there a way to add a background to the text? When I open the chest I want a long message to show, sort of like a letter, and I'd like there to be a solid color in the background. I tried adding a JPanel and JTextArea but I am not very good at java so i probably did it wrong (it didnt show up).
    Also, is there a way to add multiple lines of text to the thing that pops up (again, in sort of a letter format)? when i did
    it didnt work.
    Again, thank you so much for this in depth tutorial. It is very very beginner friendly and very clear. Keep up the amazing work, I appreciate it a lot!!

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

      Hi, everything you just asked has been explained in Part 15 video. Glad you're enjoying this tutorial!

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

      @@RyiSnow oh thank you so much!!!

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

    First thank you for your tutorial, it's an awsome guide How can i put all the code into one jar file or .exe -> i just wanna send a executable file to a friend, so he can play the game :)

    • @RyiSnow
      @RyiSnow  Год назад +1

      I've uploaded a video about it!
      ruclips.net/video/h68WlAn_Vfg/видео.html

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

      @@RyiSnow thank you so much!

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

    Hello is it possible to open up a new jframe saying congratulations instead of it popping up in the middle of the screen? Also is there a way to dispose of the game jframe while opening up the congrats screen?

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

      It is possible. You can instantiate a new JFrame and dispose the old one.

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

    Greate! Thank you! :)

  • @Magnezone962
    @Magnezone962 7 месяцев назад

    How do I write if all the items like collecting all the available diamonds, are collected?

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

    Hello! Thank you so much for this, I have learned so much about how the game accually works, but I have an Issue at 11:06, line 21: "keyImage = key.image;" it says that "image" doesnt exist in key I tested it also with door object and it still does not work, the BufferedImage in superobject class is public (image) so I would really need your help!
    Edit: Sorry i had put image(); not image; so eclipse tought it was a method :) Honest mistake *Love your vids*

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

    Good evening sir. I was planning to make different characters with different abilities, but I don't know how to make that idea possible. I'm the guy from school who will use your project for my final exam. Any advice for me to do that? I was planning to put the character selection in the front screen (after pressing start). :) Thinking of Brawler, Swordsman, Archer, and Magic Caster. Just a character selection is my problem I guess due to everything in the game is good and I followed. I just don't know now how can I make character selection.

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

    Besides your tutorial do have any other resources that can help? I have try to develop a 2d game before but the engine got complex and so did the music.

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

      I'd recommend you to check a website called ZetCode. It's pretty great!

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 года назад

    Thanks!

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

    for some reason i need to divide textLength by 5 to achive same effect, cant even figureout why. According to that what I see on your video and what I read on stackoverflow should it should give me string witdth by, it doesnt.

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

    Hey, the font don't change, I didn't put anything in the place where you inserted "Arial" and still the txt appeard like yours. I tried insertin a custom font, but nothing chaged

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

    I get a weird sound when I collide with a door without a key. I have not added that sound to the code. How does Java just produce a sound without me even writing the code. I'm confused

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

    Hi, would you be making a survival 2d game in the future?

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

      I might be. Can you be more specific? Like what game?

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

      @@RyiSnow Like building a house, eating, fighting monsters, surviving the day

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

      @@bluethemcguy4430 i know what you mean by looking at your pfp ;)

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

    Hey , I created a jar file and converted it to .exe file but once i open it the game just stops after 0.02 sec . pls help

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

    how can i write the method drawString ?

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

    Thank you for the wonderful tutorial so far! My only concern is that I can't seem to get my game to work as a runnable jar file. I also can't get the jar file you provided to run either, so I'm not sure what I should do about this. Any advice would be appreciated!

    • @victoriousprue3648
      @victoriousprue3648 Год назад +1

      I discovered what the problem was by creating a .bat file to find the errors. Apparently, even though in Java the program could path to the asset files, like tiles and sounds, in packages the jar file could not. To fix this I had to move all the assets to the src and recode the paths in the various classes that called those files.

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

    I added the drawString() and if I use it with setFont() it produces a white screen for 1 sec (noticeable ) every time I open the game. do you know why and if you know can you offer a solution please?

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

      me too

    • @mohamed-alimessedi3
      @mohamed-alimessedi3 Год назад +1

      Yes same problem for me.

    • @mohamed-alimessedi3
      @mohamed-alimessedi3 Год назад +1

      I found a way to make it quicker, seems to be MacOS specific. In the UI class, add a method called loadFont where you will load the font from a ttf file, and then call that method in the constructor. That way is much faster.

  • @cina-tech
    @cina-tech 2 года назад +1

    太棒! I just need to know whether it is possible to transfer this game to the android platform?

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

      多謝! Android uses different classes to create GUI so you need to do a little adjustment but the basic concept such as how game loop works etc. is the same. So if you are already familiar with the basic Android GUI system, it won't be too difficult to transfer.

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

    Hey I can not seem to get the text (16:27) to disapear could you help me?

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

    I think y coordinate for draw string is still the top left corner, but instead of being 50 px from the top of the panel, it's 50 px from the top of the frame.

  • @Akariiinnn
    @Akariiinnn 11 месяцев назад

    I noticed that translations can sometimes be really innacurate in titles and or description when it comes to French, i can help with that if you need someone, i don't know if those translations or automatic or something, but I can help I think.

    • @RyiSnow
      @RyiSnow  11 месяцев назад

      Yes, unfortunately all of them are automatic translations. If you don't mind, could you please write them (video title translation) in a text file and send it to me?
      You can send it via email (learningryi@gmail.com) or upload it here: drive.google.com/drive/u/0/folders/1HcwLBQzqfw8Z1FK30-c4-Zy6wp5TSS9x
      I will make sure to credit your name in the video description. Thank you!

    • @Akariiinnn
      @Akariiinnn 11 месяцев назад

      @@RyiSnow I sent it in the google docs, i'll keep updating it

    • @RyiSnow
      @RyiSnow  11 месяцев назад

      Thank you so much! I will update the title tomorrow!

    • @RyiSnow
      @RyiSnow  11 месяцев назад

      Updated the titles. Thank you so much for your help!

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

    can i use this for presentation in my class?

    • @RyiSnow
      @RyiSnow  6 месяцев назад +1

      Of course!
      Here are the guidelines: docs.google.com/document/d/1qcafOofpXYd_QPr95qbgfb1GYxXKgSZb/edit

  • @abd-elrahmanmahmoud3167
    @abd-elrahmanmahmoud3167 2 года назад

    hello sir, please i need your help in little thing in my college project

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

    Event is the key

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

    The text is not showing for mw at the end "congrats" "you found the treasure"

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

      nvm I found it it was supposed to be
      int message = 0;
      i had
      int message;

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

    My highscore is 16,25!

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

    isnt it easier to just do a textLength = text.split("").length instead of textLength = (int) g2.blablabla?

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

      wait its nto the same thing. huh.

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

      ohh its the texts width in pixels not in characters.

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

    My high score is only 29.08 seconds. I think I can do better!

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

      wow that's super fast! I never thought you can beat the game under 30 seconds lol My best score was like 30.30

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

    im on 15:30

  • @sergiosanchez-tn2pu
    @sergiosanchez-tn2pu 10 месяцев назад

    ME GUZTA

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

    Nice tutorials, but when a sound is played too much it throws java.lang.IllegalStateException: Clip is already open with format PCM_SIGNED 48000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian and frame lengh of 18240

  • @masterdob7600
    @masterdob7600 Год назад +1

    @ryisnow is it ok if I skip some steps to get the game to exactly how I want.

  • @rahatturmyshov8960
    @rahatturmyshov8960 Месяц назад

    Hello всем русскоговорящим. Если у вас проблемы с DecimalFormat и выводом запятой вместо точки, добавьте:
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US); а затем:
    DecimalFormat dFormat = new DecimalFormat("#0.00", symbols);

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

    for the music in my code i did this:
    package audio;
    import java.net.URL;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.Clip;
    import javax.sound.sampled.FloatControl;
    public class Sound {
    Clip musicClip; //open audio files
    Clip soundClip;
    URL soundUrl[] = new URL[30]; //store file paths of sound files

    public Sound() {
    soundUrl[0] = getClass().getResource("/music/BlueBoyAdventure.wav");
    soundUrl[1] = getClass().getResource("/sound/coin.wav");
    soundUrl[2] = getClass().getResource("/sound/powerup.wav");
    soundUrl[3] = getClass().getResource("/sound/unlock.wav");
    soundUrl[4] = getClass().getResource("/music/fanfare.wav");
    soundUrl[5] = getClass().getResource("/sound/walk.wav");
    }

    public void setMusicFile(int i) {
    try {
    //FORMAT TO OPEN AN AUDIO FILE IN JAVA
    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundUrl[i]);
    musicClip = AudioSystem.getClip();
    musicClip.open(audioInputStream);
    }
    catch(Exception e) {
    e.printStackTrace();
    }
    }
    public void setAudioEffectFile(int i) {
    try {
    //FORMAT TO OPEN AN AUDIO FILE IN JAVA
    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundUrl[i]);
    soundClip = AudioSystem.getClip();
    soundClip.open(audioInputStream);
    }
    catch(Exception e) {
    e.printStackTrace();
    }
    }
    public void playMusic() {
    setVolume(musicClip, 0.30f);
    musicClip.start();
    }
    @SuppressWarnings("static-access")
    public void loopMusic() {
    musicClip.loop(musicClip.LOOP_CONTINUOUSLY);
    }
    public void stopMusic() {
    musicClip.stop();
    }

    public void playSoundEffect() {
    setVolume(soundClip, 0.40f);
    soundClip.start();
    }

    //CONTROL SOUND OF MUSIC AND SOUND EFFECTS

    public float getVolume(Clip clip) { //0.0F to 1.0f
    FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
    return (float) Math.pow(10f, gainControl.getValue() / 20f);
    }
    public void setVolume(Clip clip, float volume) { //0.0f to 1.0f
    if (volume < 0f || volume > 1f)
    throw new IllegalArgumentException("Volume not valid: " + volume);
    FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
    gainControl.setValue(20f * (float) Math.log10(volume));
    }
    }
    in the sound class i added to clips, one for music and the other one for sound effects, i also add a controller for the volume with a code that i discover on the internet, in my case i doesn't have the problem that you have with music, when i stop the music sounds are still function normally, but i don't know i want your opinion of this piece of code, Both solutions are okey? or yours is better.

  • @janrui2477
    @janrui2477 Год назад +1

    I made Conway's game of life using the knowledge I had with the past ten tutorials!! I still haven't implemented any mouse listener though and I'm struggling to make the thread stop and start again.. I'm looking forward to what the next tutorial is hopefully I can use it to improve the game of life...
    Here's the game of life if anyone is interested:
    drive.google.com/file/d/1KtC-42W2QDMvlsfjcc46KX5k2DMq6twn/view?usp=sharing