Show Posts
|
|
Pages: [1]
|
|
1
|
Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress
|
on: 2010-06-11 01:51:33
|
Sound doesn't have to be complicated, either. The easiest option is probably my SoundSystem Library (perhaps overkill for your project, but very easy to use). You would need the SoundSystem core, LibraryJavaSound plug-in, and a codec plug-in ( CodecWav, for example). Assuming you have sound files named "punch.wav" and "kick.wav", you would compile them into your JAR in a package/directory named "Sounds". Here is Demonpants' example with sound effects added in: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| import paulscode.sound.SoundSystem; import paulscode.sound.SoundSystemConfig; import paulscode.sound.SoundSystemException; import paulscode.sound.libraries.LibraryJavaSound; import paulscode.sound.codecs.CodecWav;
SoundSystem mySoundSystem;
public class MyWindow extends JFrame implements KeyListener { public void initSound() { try { SoundSystemConfig.addLibrary( LibraryJavaSound.class ); SoundSystemConfig.setCodec( "wav", CodecWav.class ); mySoundSystem = new SoundSystem(); } catch( SoundSystemException sse ) { sse.printStackTrace(); } }
public void quickPlay( String filename ) { mySoundSystem.quickPlay( false, filename, false, 0, 0, 0, SoundSystemConfig.ATTENUATION_ROLLOFF, SoundSystemConfig.getDefaultRolloff() ); } public void keyPressed(KeyEvent e) { int i = e.getKeyChar(); if (i == KeyEvent.VK_UP) { } }
public void keyReleased(KeyEvent e) { int i = e.getKeyChar(); if (i == KeyEvent.VK_A) { System.out.println("Punch!"); quickPlay( "punch.wav" ); } else if (i == KeyEvent.VK_B) { System.out.println("Kick!"); quickPlay( "kick.wav" ); } }
public void keyTyped(KeyEvent e) {} |
Sorry, is it possible to explain this with more depth? The other way didn't end up working in the end  Thanks.
|
|
|
|
|
3
|
Game Development / Game Play & Game Design / Fighting Game Health Bars
|
on: 2010-06-09 00:23:26
|
Hey, I'm trying to make two health bars for my fighting game, I need to make it so when either get hit the one that gets hit the health goes down. Anyone point me in the right direction or help me out here? Thanks In Advance. 
|
|
|
|
|
5
|
Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress
|
on: 2010-06-08 00:34:04
|
I've never used AudioClip myself, to be honest. Is there a limitation with this class preventing you from creating and playing a couple of AudioClip's for your "Fight!" sound and the background music, somewhere at the beginning of your program (say in the init() method)? 1 2 3 4 5 6
| try { getAudioClip( getCodeBase(), "FIGHT!!!.wav" ).play(); getAudioClip( getCodeBase(), "myCoolMusic.wav" ).play(); } catch( Exception e ){} |
I'm assuming AudioClip's play in the background (according to JavaDoc they play on their own thread). Is that not the case, or are you only able to play one at a time or something? This actually worked perfectly for me, I just need to find out how to loop the song after the song ends. 
|
|
|
|
|
7
|
Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress
|
on: 2010-06-04 00:12:51
|
|
Also if I wanted a sound to play right at the beginning to say like Fight! or something like that how would I just add that to play once at the very beginning and then not play anymore till the next time it is played, or make it so at the end of the game it says You Win! Thanks for all the help
|
|
|
|
|
10
|
Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress
|
on: 2010-06-03 00:45:28
|
I appreciate the help you guys, I found something that seems to be working for it so far, but is this okay or do I need to do something more complicated? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import java.awt.*; import java.applet.*;
public class Project30 extends Applet { Image Buffer; Graphics gBuffer; boolean pressedLeft, pressedRight, pressedUp, pressedDown; AudioClip mySound1; AudioClip mySound2; AudioClip mySound3; AudioClip mySound4; AudioClip mySound5;
public void init() { Buffer=createImage(size().width,size().height); gBuffer=Buffer.getGraphics();
try { mySound1=getAudioClip(getCodeBase(),"punch.wav"); mySound2=getAudioClip(getCodeBase(),"kick.wav"); mySound3=getAudioClip(getCodeBase(),"punch2.wav"); mySound4=getAudioClip(getCodeBase(),"punch3.wav"); mySound5=getAudioClip(getCodeBase(),"sword.wav"); }
catch (Exception e){} }
public boolean keyDown(Event e, int key) { if(key==Event.LEFT) pressedLeft=true;
if(key==Event.RIGHT) pressedRight=true;
if(key==Event.UP) pressedUp=true; if(key==Event.DOWN) pressedDown=true;
if(key=='s'||key=='S') mySound1.play();
if(key=='e'||key=='E') mySound2.play(); if(key=='r'||key=='R') mySound3.play(); if(key=='q'||key=='Q') mySound4.play(); if(key=='d'||key=='D') mySound5.play(); if(key=='9'||key=='9') mySound5.play(); repaint();
return true; } |
|
|
|
|
|
11
|
Java Game APIs & Engines / Java Sound & OpenAL / Sounds On Keypress
|
on: 2010-06-02 00:13:26
|
Hey everyone, I'm new to this website and also kinda new to Java but am using BlueJ to code a game as a side project. I am making a 2d Fighting Game. I don't know how to make it so when it punches it makes the sound, so like A and D to walk left and right across the screen and E for punch and R to kick, I'm trying to make it so when you press the corresponding buttons the sounds will play for either punching or kicking. Can anyone help me with this? Thanks In Advance 
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|