Sound - How to Make a 2D Game in Java #9

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

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

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

    Guys, if you have that "NullPointerException' error and see NOTHING wrong with your code, you should probably make sure to check what you named your sound directory to see if you made a mistake. You may have named the sound directory "sounds" instead of just 'sound". That's what I did and didn't realize I did after hours.

    • @tofame4291
      @tofame4291 11 месяцев назад +4

      Using the fact that it's the 2nd comment from the top:
      In case of that error:
      Exception in thread "main" java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.clip" is null
      and for example "res" folder not being marked as "res" (its for example impossible in visual studio code) then line of the code should look like that:
      soundURL[0] = getClass().getClassLoader().getResource("res/sound/BlueBoyAdventure.wav");
      (see the getClassLoader() and "res/sound..." path)

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

      you dont know how much time you saved me thanks to this comment ! thank u

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

      The opposite happened to me 😅

  • @kamisama1712
    @kamisama1712 Месяц назад +3

    even though I have sounds from last time I'm gonna recreate them all. this is a tutorial I will come back too every few years. eventually I'll make my kids learn from your tutorials. You are the best Ryi

  • @IrohaNatsumeMyBeloved
    @IrohaNatsumeMyBeloved 11 дней назад

    one part of the soul of a game is the music, I'm so happy i get to choose what bgm to play in my game.

  • @casuale1200
    @casuale1200 3 года назад +34

    What you do is very cool, continue!)

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

    i am using a different map, different tiles etc and game is getting better and better.I am so grateful.You are legend.

    • @olaoluwa7905
      @olaoluwa7905 8 месяцев назад +1

      where did you get the tiles , did you draw your own?

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

      @@olaoluwa7905 u can find free tilesets or character whtever u want.I learned Paint 3D a bit and added something for my tiles and characters

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

      @@olaoluwa7905 i downloaded assets then i cut them into the tiles 64x64 pixels it was a bit hard for me at first

  • @dahoodgnome
    @dahoodgnome Год назад +6

    I'd like to replace the image of the door with an opened door after opening it with a key. This is proving more difficult then I anticipated.

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

    The music you do are just incredible !!!

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

      Glad you liked it!

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

    I am coming in late to this community, but I am sure glad I found this channel. Very good videos and very informative. I have had a light bulb moment with regards to video game design that I have not had with any other instructional tool (books, videos, classes, etc....). I can't wait to finish all the videos and then hopefully take what I have learned and apply that to making my own game. 本当にどうもありがとうございます。

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

      どういたしまして!

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

    You went hard on the BlueBoyAdventure sound

  • @RocketPokeMMO
    @RocketPokeMMO 8 месяцев назад +2

    Idk if this is addressed later in the series, but if you want to adjust the volume of the music and sfx- this is how I did it. You basically just make multiple play methods with different gain controls public void playSFX() {

    FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
    gainControl.setValue(-10.0f);
    clip.start();
    }
    public void playMusicControlled() {
    FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
    gainControl.setValue(-30.0f);
    clip.start();
    }

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

    aditionally to the speedup of the boots i also increased the switchintervall of the walking animation. Otherwise it looks like hes doign REALLY BIG STEPS! :D for that i added a maxSpriteCount integer in Player (right now if spriteCount > 12 then change spriteNum) and inserted it in the if statement to be able to change it ->int maxSpriteCount = 12 -> if(spriteCount > maxSpriteCount)... and on picking up the boots maxSpriteCount -= 3 looks natural. Great work Ryi im lovin' it!

  • @焼きそば-r2n
    @焼きそば-r2n 2 года назад +10

    If anybody is having the error 'Cannot invoke "javax.sound.sampled.start()" because "this.clip" is null' and has the code right it's probably because you don't have a sound card in your computer (kind of a stupid error I know) , and of what i've searched there isn't really a fix to this. If anybody knows a way to fix this let me know! GREAT VIDEO RYISNOW keep up the amazing hardwork!!

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

      did you found solution?

    • @焼きそば-r2n
      @焼きそば-r2n 2 года назад +1

      @@sebisek not really :(

    • @焼きそば-r2n
      @焼きそば-r2n 2 года назад +1

      @@sebisek not really, sorry :(

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

      yi dont know if this is still relevant but i had the same problem and i just had to put my audio files into a package that is where i keep my images

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

      @@cosmnick2805 thanks I'll try that

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

    Just set `speed += 8;` with my boots, and it's as awesome as you think it might be. :D
    Seriously, as someone who has been writing Java for 25 years, this is really nice work!

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

    Love the music...

  • @midi-piano8365
    @midi-piano8365 2 года назад +10

    Hey!! first of all a big thank you to you for this video series. you really explain everything to the smallest detail. can you maybe explain how i can make the speed effect work for a certain time? for example like a potion that increases the speed only for a certain time. Best regards!

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

      Check the comment thread between me and candiwandi in the Answering Requests video! I've answered a similar question there. Glad you liked the series!

  • @imjustamemerbro1506
    @imjustamemerbro1506 5 месяцев назад +3

    guys, do any of ya'll know why mine doesn't play any music despite no errors and followed the video to the exact letter? my suspect is the sound file I'm using but I converted it to 16 bit wav file so I totally have no idea why it doesn't play anything.

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

    i joined a jam about teamseas and developing game . i almos done but i need sound for be ready . i tried a few thinks but they are didn't work but this video is helped me .

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

    This is the masterpiece! Your tutorial is amazing. You inspired me to build my own 2D game project. Thank you, Ryi!

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

    Maybe you could add a utility when you press "crtl + x" or something it will show display your characters current location or something like that. Would be helpful for finding where to place items when you add boots on the map or something like this.

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

      That's actually a good idea. I think I'll do that. Thank you for the suggestion :)

  • @nowyuosee3
    @nowyuosee3 3 года назад +11

    Ryi you're a legend

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

    You are good at doing soundtracks too, lol!

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

    Great tutorial, really helped me get an intuitive understanding of implementing the sound system.
    Follow up question, do you ever use the stop function for sound effects?

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

    If anyone on Linux has the issue that the clip is null, don’t use the flatpack version op eclipse and switch to the version on the site, if wen switching suddenly many errors appear by the code, make sure you have the JDK installed of the same version of the JRE that the flatpak used( you can see the version in eclipse by your project where it sais JRE System Library and then it Sais in brackets the version)

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

    Amazing 👏🏻👏🏻👏🏻👏🏻, you'd implement an asset manager !

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

    Nice video as always thx a lot. But I have a question could you put the obj sprites and the musik files into the Google drive where you put the character sprites that would help me a lot I'm bad at that stuff

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

      No problem! I just uploaded the object and the sound files so feel free to use them:
      drive.google.com/drive/folders/1OBRM8M3qCNAfJDCaldg62yFMiyFaKgYx?usp=sharing

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

      @@RyiSnow thx a lot sry to bother you

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

    Thank you very much for your tutorial! Do you also explain e.g. to increase speed only for maybe 10 sec?

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

      Sure there are various ways to do that. 10 sec means 600 frames (if FPS is 60) so you can count frames like you do for switching sprites. For example, create a boolean boostOn and set it true when you get the boots. While this boolean is true, increase your speed. After 600 frames, set the boolean false.

  • @mikemazanetz4183
    @mikemazanetz4183 8 месяцев назад +1

    super music, so classic. Question. If I wanted to be able to toggle on/off just the music how do you do this and lose all sound output?

    • @kingwes987
      @kingwes987 Месяц назад +1

      If still have this question, RyiSnow actually has a video on sound control and in it he explains how to make a mute button

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

    I have implemented the sounds. I have the music playing on loop. It seems after my player interacts with a key or the boots, the sound will replay after the track loops, like the sound is getting put into a loop after collecting the item. Not sure what is causing this.

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

      Turns out the files exported from Beepbox with 4 'bars' or passes worth in length. Trimmed the audio file using Audacity so that it would play once.

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

    thanks for helping me!
    i sucked at making the music but i think its decent :D

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

    hey, I fave watched 9 videos of your series, I love to leanr how to add music to the game, but why when I creat my own music file on Beetbox with loop is 1, when I add it to the game, the background music is played only 1 time

  • @ngocvinh1108
    @ngocvinh1108 2 года назад +39

    I'm having a school project right now and your tutorial helps a lot. Thanks you so much and keep up the good work (☞^o^) ☞

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

      Glad I could help! That's a nice emoji ;)

  • @Prod_Ethan.
    @Prod_Ethan. Месяц назад

    Hey been loving following along your series! I have a problem with loading my music into the sound package. i know I need the file to be wav and 16bit however even with these attributes the wav is loaded into the package as a text file, any solutions on this?

  • @liz.capella
    @liz.capella Год назад

    Your tutorial save my day! THANKS!

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

    This helped me a lot in my class project!!!

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

    Wow, it is really nice. I was just interesting how to work with sounds, but I watched the full video XD thanks

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

    Wow this is a great resource for me. Thank you very much. Helps a lot

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

    Hello! I love this series... thank you so much for taking your time to make, post and explain all the things you do in your channel :) I use linux, so maybe it's a specific problem ( I haven't seen anyone else mention it... maybe I missed it. ) but, if I click the enter key really fast in a fight with a slime, a bunch of times, ( I'm actually on #25 ) eventually, my sound stops playing. The only way I can get it back is to close the game and restart. I have tried since this episode to correct it myself, by using the stop or close methods in the Java docs about clips, but, I cannot seem to fix it. I am sorry if I am not being clear or if it is just linux specific and you can't reproduce. I will keep trying myself, although I am very new to Java games. Again... thanks for your time and sorry if I am being "new". lol

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

      So the issue happens only when you type the key really fast?

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

      @@RyiSnow Actually, no... it always does it. Sorry... that's what I was doing when I first noticed it, though. Doesn't matter what speed I go. I have uploaded an unlisted video showing the problem here... ruclips.net/video/_JN2O0mvK7A/видео.html Let me know if you can't access it. Thanks!

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

      @@MorrowHopeMusic ​ @RyiSnow I have the same issue, did you find a solution? I'm in linux and found the same problem. What I found is this error "javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported."
      But at first everything works right and after reproducing many sounds it fails at some point. It doesn't seem to be a problem with an specific file, it happens with any of them.

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

      @@TORMENTUMM Hi! If you follow the link I posted in the reply above, you will see the solution I finally used 👍 I hope it helps you.

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

      @@MorrowHopeMusic your solution works cool but im still having the same sword issue :s. Anyways, thanks for your help!

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

    Hi! Thank you for making this series sir! I'm just confused why my (bg music) sound doesn't play even if it is correct, the size of the wav file is just 2.92 mb, i don't know if it is because of the size of the file but when i play my sound effects it plays, its just the bg music that does not play and loop. How can I fix that?

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

      Are you getting any error messages?

    • @SimratKaur-o3r
      @SimratKaur-o3r Год назад +1

      @@RyiSnow im having errors too,im getting a null pointer exception for some reason

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

    Hi hello, question: Will you use polymorfism anywhere in this code? Thanks ! (interfaces (whole project))

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

    Nice and great work

  • @pyckleedits.
    @pyckleedits. Год назад +1

    Hi Ryi! I've been coming across an error in the code reading "Exception in thread "main" java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.clip" is null" I've reread through most of my code and have no idea how to fix this, any suggestions?

  • @Artem-libra520
    @Artem-libra520 2 года назад

    Thank you very much. Your video is very useful, we learn a lot from it and because of it,we deal with our project 👍

    • @Artem-libra520
      @Artem-libra520 2 года назад

      btw,if you don't mind it, it's better to say 我會說一點點中文 we are not use to say 我會說中文一點點sorry for bother you, i notice it today xd

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

      Ah thanks! I will correct it!

    • @Artem-libra520
      @Artem-libra520 2 года назад

      @@RyiSnow You are welcome.我會說一點點中文=i can speak a little bit of Chinese. 我中文说得不太好=I can't speak Chinese very well. 一點點 is adj. or n.like我會(說)一點點。

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

    thank you for making these nice Videos! Please go on like that :D

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

    You are awesome RyiSnow, I'm doing a Unii project your sound system is far simpler than the way they gave us to do it, I'm using you sound code and set it with a JMenubar slider, thanks so much, And I make sure to give you credit for your hard work!! Please keep this project up n RUclips as many people love it. Are you planning on a new project in the future? what about a hexagon dynamic map? Appreciated!

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

    how do to stop a Loop or playMusic ?

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

    how to add sound while player walk(footstep sound)? I try to add gp.playSE in KeyHandler and in update() but it error

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

    Um, i don't know what's wrong but even after going and copying your code letter by letter there's this error that says:
    Exception in thread "main" java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.clip" is null
    i don't know what is causing it to be null, i eventryed using different ints and giving the value zero but it still gives the same error

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

      maybe in the Sound class you made a public void method Sounds instead of a constructor? at least there is something wrong when the sounds are being imported and/or put in the soundsURL array

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

      ​@@hesselagema4515 I'll check about the soundsURL but the Sound is a constructor
      Edit: i checked the soundURL, it's without the s, and it isn't because of that, this happens cuz of the "clip.start();" in play(), this also only happens after i run the program, and doesn't show any error while actually editing

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

    for some reason my powerup and unlock sounds arent working, and i dont know why, key and music are fine i checked for typos n nuthing, im a lil confused?

  • @DmytroHadomskiy
    @DmytroHadomskiy Год назад +8

    Who have a problem with a file in new Java versions(like can't invoke or cant find a file):
    Change URL[] soundURL = new URL[30]; --------> File[] soundURL = new File[30];
    & soundURL[] = get.Class().get.Resource("res/sound/BlueBoyAdventure.wav") --------> soundURL[0] = new File("res/sound/BlueBoyAdventure.wav");

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

    Thank you RyiSnow!

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

    it gives me this error: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.clip" is null

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

      Sounds like the program cannot refer to the sound file. Maybe the file name is not typed correctly or placed in a different location.

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

      @@RyiSnow I placed the files in the res folder, and in the song folder, i dubt that the name of the file is wrong because I copy pasted it :/

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

    From where we can get game sound website please

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

    I got java out of memory error related to direct clip when i play too many dialogue that play speak sfx each letter

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

    hi ryisnow, I don’t know why I’m writing this, but maybe it will be useful to someone: I exactly copied the code from the video and I, like many others, had an error with clip start(); = null. I tried to solve this error in different ways, in particular comments under the video, but the error remained. In the end I decided to do a small test: I loaded your sounds from the game, instead of mine written on flstudio, and everything worked as it should! I I still didn’t understand why my audio files were not read, because they had the same wav format. If anyone knows the reason, I would be grateful.

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

    I want to add sound in the menu when I change from "NEW GAME", "LOAD GAME", and "QUIT"! Like a chime sound! I tried it myself and it just loops over and over!

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

    hey im getting "Cannot invoke "javax.
    sound.sampled.Clip.start()" because "this.clip" is null" error anyone know how to fix it?

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

      do you already have solution for that error?

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

      @@nateenese no

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

      @@sebisek I have solution by that, just change soundURL with this
      File f = new File("your absolute path");
      AudioInputStream audioIS = AudioSystem.getAudioInputStream(f.toURI().toURL());
      Hope it'll work for you

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

      @@nateenese do I have to put the literal code you have written?

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

      @@nateenese can you please paste the whole code here

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

    Thank you so much!! :)

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

    thenks!

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

    Thank you sm!!!

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

    This was usefull for my game ;D

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

    Thanks!

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

    If I want the shoe / flash / anything to only last for 10 seconds, find an easy way to fix it?

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

      Yes, since the game runs on 60 fps, 60 frames means 1 second and you can use that to count time.
      Example:
      (In Player class)
      // Create variables
      boolean bootsOn = false;
      int bootsCounter = 0;
      Then when you get the boots, instead of increasing the speed, change the bootsOn to true;
      //speed += 1; // remove this line
      bootsOn = true;
      Then inside of the update(), type like this (outside of the keyPressed if statement):
      if(bootsOn == true) {
      speed = 5;
      bootsCounter++;
      if(bootsCounter > 600) {
      bootsCounter = 0;
      bootsOn = false;
      speed = 4;
      }
      }
      This way the boots' effect only last 10 seconds. I think this is a very cool idea :D
      Not exactly like this but we will do a similar thing in Part10. We will count play time so we can enjoy time attack!

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

      @@RyiSnow thanks i have done it like that thanks again i have learn a lote from you. Im studing to become Java developer in sweden .

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

      Hallå, that's cool! I think you're getting there. You're not just copying my code but thinking on your own and expanding it. That's a very important talent :)

  • @HuyNguyen-cb9uo
    @HuyNguyen-cb9uo Год назад

    I thank you very much for the knowledge you have conveyed, they are very good and useful.
    But your program is very confusing, when I try to make a new program, there are many shortcomings. Can you make a UML diagram to summarize the program. Sincerely thank. Wishing you good health and happiness in life

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

    you're really cool huhu :)

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

    Does anyone have a " javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported. " error after playing the sounds many times ?

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

      Got the same error... did you find a solution?

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

      I couldn't find an easy solution. I modified the class Sound quite a lot.
      Basically, instead of loading the audio file every time we want to play a sound, I load them all at the initialisation of the game and play them when needed. To this end, I had to change the clip and the floatcontrol into arrays. I also had to call the method setFile in the constructor. Therefore I had to remove the call of setFile in the methods playSE and playMusic of the GamePanel class.
      I don't know if it's an optimised solution (I have more variables but less calls to the setFile method) and maybe I forgot some other things I changed but it worked for the little game I wanted to do!

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

      package main;
      import java.io.IOException;
      import java.net.MalformedURLException;
      import java.net.URL;
      import javax.sound.sampled.AudioInputStream;
      import javax.sound.sampled.AudioSystem;
      import javax.sound.sampled.Clip;
      import javax.sound.sampled.FloatControl;
      import javax.sound.sampled.LineUnavailableException;
      import javax.sound.sampled.UnsupportedAudioFileException;
      public class Sound {
      int soundNum = 30;
      Clip clip[] = new Clip[soundNum];
      URL soundURL[] = new URL[soundNum];
      FloatControl fc[] = new FloatControl[soundNum];
      int volumeScale = 4;
      float volume = 1f;

      public Sound() {
      soundURL[0] = getClass().getResource("/sound/powerup.wav");
      soundURL[1] = getClass().getResource("/sound/coin.wav");
      .
      .
      .
      for (int i = 0; i < soundURL.length; i++) {
      if (soundURL[i] != null) {
      setFile(i);
      }
      }
      }
      public void setFile(int i) {
      try {
      AudioInputStream ais = AudioSystem.getAudioInputStream(soundURL[i]);
      clip[i] = AudioSystem.getClip();
      clip[i].open(ais);
      fc[i] = (FloatControl) clip[i].getControl(FloatControl.Type.MASTER_GAIN);
      checkVolume();
      }
      catch (MalformedURLException e) {
      e.printStackTrace();
      throw new RuntimeException("Sound: Malformed URL: " + e);
      }
      catch (UnsupportedAudioFileException e) {
      e.printStackTrace();
      throw new RuntimeException("Sound: Unsupported Audio File: " + e);
      }
      catch (IOException e) {
      e.printStackTrace();
      throw new RuntimeException("Sound: Input/Output Error: " + e);
      }
      catch (LineUnavailableException e) {
      e.printStackTrace();
      throw new RuntimeException("Sound: Line Unavailable Exception Error: " + e);
      }
      }
      public void play(int i) {
      clip[i].setFramePosition(0);
      clip[i].start();
      }
      public void loop(int i) {
      clip[i].loop(Clip.LOOP_CONTINUOUSLY);
      }
      public void stop(int i) {
      clip[i].stop();
      }
      public void checkVolume() {
      switch(volumeScale) {
      case 0:
      volume = -80f;
      break;
      case 1:
      volume = -20f;
      break;
      case 2:
      volume = -12f;
      break;
      case 3:
      volume = -5f;
      break;
      case 4:
      volume = 1f;
      break;
      case 5:
      volume = 6f;
      break;
      }
      for (FloatControl fc : fc) {
      if (fc != null) {
      fc.setValue(volume);
      }
      }
      }
      }

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

    i use two different music in my game, how do I stop one of the music so that both music does not sound at the same time?

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

      You can call the stopMusic method

  • @erronisamuel1973
    @erronisamuel1973 7 дней назад

    anyone having the this.null error just change the package name to sounds and you wont get the error

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

    "first half".... checks playlist.... 51 videos left

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

      The second half was supposed to have 15 videos or so (25 videos in total) in my initial plan but new ideas/requests kept coming up and it didn't go as planned 😅

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

      @@RyiSnow im actually glad! Having a lot of fun with this! I will try to complete it all

  • @bradleybeal9354
    @bradleybeal9354 11 месяцев назад +1

    8:00

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

    This is very cool, can you make tutorials about networking and multiplatform in this game?

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

    cant you link the code in the descripion? i get an error Cannot invoke "javax.sound.sampled.start()" becuase "this.clip" is null

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

      sorry it was a typo.

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

      ​@@mastergamer4335​i am getting this error too, what typo did you make? is it in the file path?

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

      try with this works for me soundURL[1]= (new File("sounds/file.wav").getAbsoluteFile()).toURL();

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

      @@nao8595 did you fix it?

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

      how did you fix it?

  • @progress2171
    @progress2171 Год назад +4

    If anybody is getting the error 'Cannot invoke "javax.sound.sampled.start()" because "this.clip" is null' I FOUND A SOLUTION:
    public Sound(){
    try {
    soundURL[0] = new File("res/sound/BlueBoyAdventure.wav").toURI().toURL();
    soundURL[1] = new File("res/sound/coin.wav").toURI().toURL();
    (add all your files)
    } catch (IOException e) {
    // TODO: handle exception
    e.printStackTrace();
    }
    }
    this worked for me let me know if it works for you :D

    • @wilshun143
      @wilshun143 11 месяцев назад +1

      thank you, you were the last comment for me and you saved me :DD

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

      thank you, I had to do something similar when we set tiles. You saved a lot of people time I guarantee it.

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

    getting No line matching interface Clip supporting format PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian is supported. error. followed code exactly, paths are correct and files play sounds in a media player. Not sure what's wrong here.