Hi, gouessej! Thanks for testing the game. I’d be very grateful for any further testing you could do to help me get rid of those bugs.
To test the sound, I’ve uploaded a new version of the JAR in which one of the sound effects is loaded from a WAV rather than an OGG file. If you hear a sound when the mouse pointer moves over one of the buttons on the title screen, then I’m playing WAV files correctly and it’s the OGG files that are the problem.
I’m loading the sound effects into Clip objects and playing them with
clip.stop();
clip.flush();
clip.setFramePosition(0);
clip.start();
For WAV files, the code to load them is
AudioInputStream audioStream = AudioSystem.getAudioInputStream(url);
clip = AudioSystem.getClip();
clip.open(audioStream);
audioStream.close();
For OGG files, I’m using Jorbis to read the file as PCM data, and then creating a Clip in the following way:
private Clip newClip(int sampleRate,
int numChannels,
byte[] pcmBytes) throws IOException {
int bitsPerSample = 16;
boolean isSigned = true,
isBigEndian = false;
AudioFormat format = new AudioFormat((float)sampleRate, bitsPerSample,
numChannels, isSigned, isBigEndian);
Clip clip = null;
try {
clip = AudioSystem.getClip();
clip.open(format, pcmBytes, 0, pcmBytes.length);
} catch ( Exception ex ) {
throw new IOException("failure during creation of Clip (" + ex + ")");
}
return clip;
}
The console output may say if there’s a problem decoding the OGG files. Could you download the JAR file and run it using the following command?
java -enableassertions -jar BunnyGolf.jar debug
The console output should then include a few lines of info for each OGG file that is loaded. For example, the last block of OGG output should look like:
Decoding Ogg Vorbis bitstream
Bitstream is 1 channel, 44100Hz
Encoded by: Xiph.Org libVorbis I 20020717
Constructing clip, 20096 bytes of PCM data
That’s all I can think of for now for debugging the sound.
As for full-screen mode, the code looks something like the following.
public class MainWindow extends JFrame {
...
GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if ( device.isFullScreenSupported() ) {
device.setFullScreenWindow((Window)this);
mIsFullScreen = true;
}
...
if ( mIsFullScreen ) {
createBufferStrategy(2);
mBufferStrategy = getBufferStrategy();
} else {
mGameCanvas.createBufferStrategy(2);
mBufferStrategy = mGameCanvas.getBufferStrategy();
}
...
}
Can you see any problem with that? The code in full is a bit convoluted (spread between several classes) so I’ll hold off posting it for the timebeing. I’m going to hunt around for some more examples of full-screen mode being used to see if those show me where I’m going wrong.
Thanks again for your help.
Simon