A Consummate Android Game Well Solution

While audible good effects together with music won't necessarily brand whatever video game to a greater extent than fun, they definitely practise acquire inwards to a greater extent than interesting together with to a greater extent than immersive. Before I added whatever sounds to my novel Android game, I didn't actually notice they were missing because I was together with therefore focused on gameplay elements. But subsequently adding them, whenever I muted my device (or disabled the good inwards code for functioning troubleshooting) it was obvious... something was missing.

Image By: Siddartha Thota


If yous desire to acquire how to code good for your Android app or game yourself, the Android developer site's Managing Audio Playback together with Media Playback pages are a expert house to start. There are besides about expert sites/blogs out in that location that bring upward how to play a unmarried good upshot or play a unmarried music file, but I had problem finding a consummate solution that handled good effects AND music, together with therefore I created an good shape that allows yous to easily play music together with good effects from whatever activity. I promise this volition assistance others wanting to acquire started amongst good inwards their Android apps/games.

My GameAudio.java file together with its code are licensed nether the Creative Commons Attribution License, pregnant yous may freely utilization it together with adjust it to your needs equally long equally yous credit me equally the master copy writer inwards a header comment. If yous wouldn't heed posting a comment hither telling me how you're using it, that would besides live actually cool together with live a expert incentive for me to portion additional code inwards the time to come :)

Download GameAudio.java equally a Zip File

View Source of GameAudio.java inwards a Pop-Up Window

Below is an Activity code snippet showing how to utilization the GameAudio class. Note the placement of the initialize together with releaseAll calls inwards onResume together with onPause, respectively. The playMusic together with playSound methods tin live called anytime subsequently intialize together with earlier releaseAll.
 ...     @Override     protected void onResume() {         super.onResume();         GameAudio.initialize(this, R.array.MenuSounds);         GameAudio.playMusic(R.raw.music_title_screen, true, 1.0f);     }      @Override     protected void onPause() {         super.onPause();         GameAudio.releaseAll();     }       world void onClick(View v) {         GameAudio.playSound(R.raw.sound_button_press); ... 
One lastly note, yous may conduct keep noticed the initialize method takes an array resources input parameter -- R.array.MenuSounds inwards the snippet above. This is done to allow the GameAudio shape to practise a mapping betwixt good upshot resources identifiers similar R.raw.sound_button_press together with the conduct keep for the loaded good created past times the SoundPool.load function. If yous alone desire to play music, yous tin travel past times naught for that array resources identifier. Otherwise, practise an entry similar the i below inwards your res/values/arrays.xml file.
                    @raw/sound_button_press         ...          ...  
So that's it, the consummate good solution I'm using inwards my upcoming Android game. I promise this helps someone else only similar the community's awesome docs, blogs, together with websites conduct keep helped me.

Subscribe to receive free email updates:

0 Response to "A Consummate Android Game Well Solution"

Post a Comment