Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress on: 2010-06-10 23: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  
// Add these imports at top of the program:
import paulscode.sound.SoundSystem;
import paulscode.sound.SoundSystemConfig;
import paulscode.sound.SoundSystemException;
import paulscode.sound.libraries.LibraryJavaSound;
import paulscode.sound.codecs.CodecWav;
//...etc

// And you'll need a SoundSystem handle:
SoundSystem mySoundSystem;

public class MyWindow extends JFrame implements KeyListener
{
    // Call initSound() from the constructor or from an initialization method:
    public void initSound()
    {
        try
        {
            SoundSystemConfig.addLibrary( LibraryJavaSound.class );
            SoundSystemConfig.setCodec( "wav", CodecWav.class );
            mySoundSystem = new SoundSystem();
        }
        catch( SoundSystemException sse )
        {
            sse.printStackTrace();
        }
    }

    // A method for quickly playing a sound file:
    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)
        {
            // Move up!
        }
        //etc.
    }

    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) {//do nothing}
}

Sorry, is it possible to explain this with more depth? The other way didn't end up working in the end Sad
Thanks.
2  Game Development / Game Play & Game Design / Re: Fighting Game Health Bars on: 2010-06-09 21:39:05
So I would have to draw/paint it every time they get hit? or can I get it so it updates all the time and when one hits the other the health goes down alone?
3  Game Development / Game Play & Game Design / Fighting Game Health Bars on: 2010-06-08 22: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. Smiley
4  Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress on: 2010-06-07 23:48:22
Ok so now how would I make it so the ouch sound would play when the characters get hit by a punch or kick?
5  Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress on: 2010-06-07 22: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. Smiley
6  Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress on: 2010-06-03 22:37:02
Lol wow I feel stupid lol. Sorry I was not paying attention to what I was saying, I already have the audioclip but how do I make background music into it?
7  Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress on: 2010-06-03 22: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
8  Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress on: 2010-06-03 22:02:48
So to use AudioClip I need to add a new thread? is that what you were saying?
9  Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress on: 2010-06-02 23:19:38
Also I would like a song playing in the background as all this is going on, how would I go about that?
10  Java Game APIs & Engines / Java Sound & OpenAL / Re: Sounds On Keypress on: 2010-06-02 22: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-01 22: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  Smiley
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!