Jump to content

Help with audiosprites, please!


Sgd
 Share

Recommended Posts

Hello! I am a noobie in phaser and I need your help!

 

I'm trying to use audiosprites but I cant make them work, really dunno why doesnt work and it's kind of frustraiting.

 

First of all this is the tool I'm trying to use: https://github.com/tonistiigi/audiosprite

 

Then, in my preloader I wrote this: 

 

this.load.json('game_audio_json', 'assets/audio/game_audio_json.json');
this.load.audio('game_audio', 'assets/audio/game_audio.mp3', true);
 
Then I have a class called AudioManager, and in the init of that class I have this (I found this code in another thread):
 
this.audio_now = this._game.add.audio('game_audio');
this.audio_json = this._game.cache.getJSON('game_audio_json');
var asm = this.audio_json['spritemap'];
for(var key in asm) {
    if (asm.hasOwnProperty(key)) {
         this.audio_now.addMarker(key, asm[key]["start"], asm[key]["end"] - asm["start"]);
    }
}

 

And finally I have this code for testing the music on my initial menu:

 

this.playThisSong = AudioManager.getInstance().audio_now;
this.playThisSong.play('menu-music');
 
audio_now from the AudioManager's class is a public Phaser:Sound.
 
The problem comes when I go to the menu and there's no music playing. The Chrome's console doesnt say anything...
 
Hope you guys can help me! Thank you!
Link to comment
Share on other sites

On the new version of Phaser (2.1.2) you can load audiosprites easily like this:

 

 

First, preload the audiosprite:

game.load.audiosprite('sound' , 'assets/sound/audiosprite.ogg' , 'assets/sound/audiosprite.json')

then,  simply create an audiosprite object in your game :

var audio=game.add.audioSprite('sound');

and easily play any sound in the audiosprite by refering to its name in the json file

audio.play('sound_1');

I think the documentation is not yet updated to inlcude Phaser.Audiosprite so read the comments in the source here : https://github.com/codevinsky/phaser/commit/dd0d1729adf4fd97b28d3d95cb670e8d101fde13

 

Edit: Corrected the messed up the key names.

Link to comment
Share on other sites

  • 4 weeks later...

I quickly checked the Phaser.Audiosprite code and it creates copies of the Phaser.Sound for each marker. Frankly I'm not too familiar with the internals how the browser does things, so I'm wondering if using the whole audio buffer for each Phaser.Sound instance is memory wise good? Especially if you got many sounds in one audiosprite and you're infact just playing one marker for each Phaser.Sound instance. Sure there's pointer to the buffer cache, but how the web audio (and especially audio-tag) behaves in a case where you got ie. 30 sounds in one audiosprite.

 

Probably need to do some testing later when I have to create better audio/music manager for the next game and solve these issues and figure out good way to choose what audio goes into what audiosprite set.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...