ekelokorpi / panda-engine

Panda Engine - HTML5 Game Engine
https://www.panda2.io
739 stars 101 forks source link

Rewrite sound module #22

Closed ekelokorpi closed 10 years ago

ekelokorpi commented 10 years ago

Lots of room for optimization, cleaner code, better syntax.

ellisonleao commented 10 years ago

How about using https://github.com/goldfire/howler.js/ ?

ekelokorpi commented 10 years ago

Hmm, I really want use external libraries as little as possible, just to keep control of how everything works.

And i'm almost done rewriting the module :)

Though Howler features look pretty nice :+1:

ekelokorpi commented 10 years ago

First version ready: https://github.com/ekelokorpi/panda.js/blob/develop/src/engine/audio.js

Syntax:

// Add audio to loader
game.addAudio('media/jump.m4a', 'jump');

// Play audio as a sound
game.audio.playSound('jump');

// Define volume
game.audio.playSound('jump', 1.0);

// Loop sound
game.audio.playSound('jump', 1.0, true);

// Define callback
game.audio.playSound('jump', 1.0, true, function() {
    console.log('Audio played');
});

// Define playback rate (only in Web Audio)
game.audio.playSound('jump', 1.0, false, false, 0.5);