Sound for jump!


(Nate ) #1

Hey guys! I am back again with another boolean related inquiry!

So I have a character, and he jumps, he is capable of double jumping. I would like a nice jump sound for either just the first jump, or both jumps. I have not decided this far yet. For now, I am trying to just have it play when he does his initial jump. Here is what I have, it does not play the sound very well, it either plays it a million times, once or twice, or not at all.

if (!Input.check(Key.SPACE) && isJumping)
		{
			doubleJump = true;
		
		}
	
		if (Input.check(Key.SPACE) && isJumping && !doubleJump)
		{
			sfxJump = new Sfx(theGameSounds.SND_JUMP_SOUND);
			sfxJump.play();
		}
		
		if (Input.check(Key.SPACE) && doubleJump && isJumping)
		{
			ySpeed = -jumpPower;
					
			isJumping=false;
			doubleJump=false;
		}

Let me know what you guys think! Any help is very much appreciated!


(Zachary Lewis) #2

There’s some problems with your logic in this code. It seems like most of your problems can be solved by working through what you’re trying to do.

Try talking aloud through what your logic should do, or write it down.

“If a player presses a button, the character should play a sound and jump. If a player tries to jump in midair and hasn’t double-jumped, the character should play a sound and jump. Any further attempts to jump should be ignored until the player lands on the ground.”

Try splitting that paragraph up into simple steps or a flow chart and see if you can’t figure out what your problem is. Good luck! :wink:


(Nate ) #3

You are right Zach! I will lay it out step by step tomorrow for now I must slumber! lol I just graduated with my bachelor’s of science in computer science with a focus in digital art you would think I could handle this lol Too much screen time and lack of sleep for today I suppose! :dancer:


(Jacob Albano) #4

This might sound silly but it’s the way I fix most of my problems: When you get stuck, don’t immediately come to post on the forums. Take a shower, go for a walk, play a video game that exercises your brain. Zach’s solution is pretty simple and wouldn’t be hard to come up with on your own.


(Nate ) #5

Yes I agree tenfold! My best ideas and solutions come to me while showering normally, or eating. Anyway, I solved this issue… it was painfully simple. I totally missed 1/4 of my jumping code in this original post, plugged the sound in there, and viola, worked like a charm! :smiley: