Audio test
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.3.0/phaser.js"></script>
JavaScript
var game = new Phaser.Game(640, 480, Phaser.CANVAS, '', null, false, false);
var game_state = {};
var button;
game_state.main = function () {};
game_state.main.prototype = {
preload: function () {
game.load.spritesheet('button', 'http://examples.phaser.io/assets/buttons/button_texture_atlas.png', 193, 71);
// ======================================== IN SCOPE
this.game.load.audio('music', 'http://examples.phaser.io/assets/audio/bodenstaendig_2000_in_rock_4bit.ogg');
// ======================================== IN SCOPE
},
create: function () {
// ======================================== IN SCOPE
var audio = this.game.add.audio('music');
audio.allowMultiple = false;
audio.addMarker('lvl1_1', 0, 1);
audio.addMarker('lvl1_2', 1, 1);
audio.addMarker('lvl1_3', 2, 1);
audio.addMarker('lvl1_4', 3, 1);
audio.addMarker('lvl1_5', 4, 1);
audio.addMarker('lvl1_6', 5, 1);
audio.addMarker('lvl1_7', 6, 1);
audio.addMarker('lvl1_8', 7, 1);
audio.addMarker('lvl1_9', 8, 1);
for (i = 1; i < 10; i++) {
console.log(i);
audio.play("lvl" + 1 + "_" + i, 0, 1, false);
console.log("iteration " + i + " on loop, attempt to play lvl" + 1 + "_" + i + ", audio.isPlaying is " + audio.isPlaying);
while (audio.isPlaying) {};
};
// ======================================== IN SCOPE
// NOT IN SCOPE
game.stage.backgroundColor = '#ffffff';
button = game.add.button(game.world.centerX - 95, 200, 'button', actionOnClick, this, 0, 1, 2);
}
};
// Add and start the 'main' state to start the game
game.state.add('main', game_state.main);
game.state.start('main');
...