Re: Implementing openal to game
Posted by
Xerxes Rånby on
Sep 04, 2013; 8:16am
URL: https://forum.jogamp.org/Implementing-openal-to-game-tp4029970p4029978.html
Dawn wrote
So. After Sources Sharing Buffers lesson 5 at your site i have made a class. And then implemented in two different classes as described below. The interesting part is that it is working, but the sad that it isn't working correct. I'm new in ( at ) Java at all so my brain ( experiences ) won't see out of this so called "my brain loop".
You should re-design your application to only initialize OpenAL and load the samples at start-up, you only need to initialize it once!
If you have a different class that needs to play audio make sure this class can access the already initialized "contest".
When your application start do:
contest = new contest();
contest.initOpenAL();
contest.loadALData();
When you create a new class that needs to play audio give it access to the "contest" using its constructor.
GameInputHandler handler = new GameInputHandler(contest);
And inside this GameInputHandler use the already initialized "contest":
else if (key == KeyEvent.VK_SPACE) {
if (System.currentTimeMillis() - lastPressProcessed > 1000) {
GameFrame.addMissle(new Missle(x, y - 5));
contest.addSource(0);
GameFrame.removeEnemy(this);
GameFrame.removeMissle(m);
contest.addSource(1);
contest.addSource(2);
You can also take a look at the main of lession5
http://jogamp.org/joal-demos/www/devmaster/lesson5.htmland see that OpenAl only needs to be initialized once.
If you need further help publish the complete source-code, under a free software license, for your game.