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.
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)
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
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. 本当にどうもありがとうございます。
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() {
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!
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!!
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!
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!
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.
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 .
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.
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?
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)
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
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
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.
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.
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
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?
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 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!
@@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.
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?
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?
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!
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
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
@@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
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?
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");
it gives me this error: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.clip" is null
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.
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 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
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!
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 :)
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
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 ?
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!
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 😅
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
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.
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.
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)
you dont know how much time you saved me thanks to this comment ! thank u
The opposite happened to me 😅
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
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.
What you do is very cool, continue!)
i am using a different map, different tiles etc and game is getting better and better.I am so grateful.You are legend.
where did you get the tiles , did you draw your own?
@@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
@@olaoluwa7905 i downloaded assets then i cut them into the tiles 64x64 pixels it was a bit hard for me at first
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.
The music you do are just incredible !!!
Glad you liked it!
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. 本当にどうもありがとうございます。
どういたしまして!
You went hard on the BlueBoyAdventure sound
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();
}
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!
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!!
did you found solution?
@@sebisek not really :(
@@sebisek not really, sorry :(
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
@@cosmnick2805 thanks I'll try that
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!
25 YEARS!?!
Love the music...
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!
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!
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.
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 .
This is the masterpiece! Your tutorial is amazing. You inspired me to build my own 2D game project. Thank you, Ryi!
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.
That's actually a good idea. I think I'll do that. Thank you for the suggestion :)
Ryi you're a legend
You are good at doing soundtracks too, lol!
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?
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)
Amazing 👏🏻👏🏻👏🏻👏🏻, you'd implement an asset manager !
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
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
@@RyiSnow thx a lot sry to bother you
Thank you very much for your tutorial! Do you also explain e.g. to increase speed only for maybe 10 sec?
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.
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?
If still have this question, RyiSnow actually has a video on sound control and in it he explains how to make a mute button
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.
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.
thanks for helping me!
i sucked at making the music but i think its decent :D
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
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^) ☞
Glad I could help! That's a nice emoji ;)
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?
Your tutorial save my day! THANKS!
This helped me a lot in my class project!!!
Wow, it is really nice. I was just interesting how to work with sounds, but I watched the full video XD thanks
Wow this is a great resource for me. Thank you very much. Helps a lot
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
So the issue happens only when you type the key really fast?
@@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!
@@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.
@@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.
@@MorrowHopeMusic your solution works cool but im still having the same sword issue :s. Anyways, thanks for your help!
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?
Are you getting any error messages?
@@RyiSnow im having errors too,im getting a null pointer exception for some reason
Hi hello, question: Will you use polymorfism anywhere in this code? Thanks ! (interfaces (whole project))
Nice and great work
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?
same here
Did you get any answers? I am stuck with the same problem.
@@achutharajr1316 No :(
@@achutharajr1316 me too
Thank you very much. Your video is very useful, we learn a lot from it and because of it,we deal with our project 👍
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
Ah thanks! I will correct it!
@@RyiSnow You are welcome.我會說一點點中文=i can speak a little bit of Chinese. 我中文说得不太好=I can't speak Chinese very well. 一點點 is adj. or n.like我會(說)一點點。
thank you for making these nice Videos! Please go on like that :D
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!
how do to stop a Loop or playMusic ?
how to add sound while player walk(footstep sound)? I try to add gp.playSE in KeyHandler and in update() but it error
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
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
@@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
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?
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");
thanks 😃
@@rafaelastolfo =)
I tried your fix and it still gives the error
@@happyburger23 Can you somehow show an error?
Thank you RyiSnow!
it gives me this error: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.Clip.start()" because "this.clip" is null
Sounds like the program cannot refer to the sound file. Maybe the file name is not typed correctly or placed in a different location.
@@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 :/
From where we can get game sound website please
I got java out of memory error related to direct clip when i play too many dialogue that play speak sfx each letter
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.
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!
hey im getting "Cannot invoke "javax.
sound.sampled.Clip.start()" because "this.clip" is null" error anyone know how to fix it?
do you already have solution for that error?
@@nateenese no
@@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
@@nateenese do I have to put the literal code you have written?
@@nateenese can you please paste the whole code here
Thank you so much!! :)
thenks!
Thank you sm!!!
This was usefull for my game ;D
Thanks!
If I want the shoe / flash / anything to only last for 10 seconds, find an easy way to fix it?
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!
@@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 .
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 :)
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
you're really cool huhu :)
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 ?
Got the same error... did you find a solution?
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!
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);
}
}
}
}
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?
You can call the stopMusic method
anyone having the this.null error just change the package name to sounds and you wont get the error
"first half".... checks playlist.... 51 videos left
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 😅
@@RyiSnow im actually glad! Having a lot of fun with this! I will try to complete it all
8:00
This is very cool, can you make tutorials about networking and multiplatform in this game?
cant you link the code in the descripion? i get an error Cannot invoke "javax.sound.sampled.start()" becuase "this.clip" is null
sorry it was a typo.
@@mastergamer4335i am getting this error too, what typo did you make? is it in the file path?
try with this works for me soundURL[1]= (new File("sounds/file.wav").getAbsoluteFile()).toURL();
@@nao8595 did you fix it?
how did you fix it?
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
thank you, you were the last comment for me and you saved me :DD
thank you, I had to do something similar when we set tiles. You saved a lot of people time I guarantee it.
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.