Skip to content

Commit c18de53

Browse files
committed
SoundManager converted and playing audio :)
1 parent ed13283 commit c18de53

8 files changed

Lines changed: 1068 additions & 794 deletions

File tree

Phaser.sublime-workspace

Lines changed: 102 additions & 792 deletions
Large diffs are not rendered by default.

examples/js.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
<script src="../src/loader/Cache.js"></script>
9393
<script src="../src/loader/Loader.js"></script>
9494

95+
<script src="../src/sound/Sound.js"></script>
96+
<script src="../src/sound/SoundManager.js"></script>
97+
9598
<script src="../src/utils/Debug.js"></script>
9699

97100

examples/sound1.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>phaser.js - a new beginning</title>
5+
<?php
6+
require('js.php');
7+
?>
8+
</head>
9+
<body>
10+
11+
<script type="text/javascript">
12+
13+
(function () {
14+
15+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
16+
17+
function preload() {
18+
game.load.image('disk', 'assets/sprites/ra_dont_crack_under_pressure.png');
19+
//game.load.audio('wizball', ['assets/mp3/oedipus_wizball_highscore.ogg', 'assets/mp3/oedipus_wizball_highscore.mp3']);
20+
game.load.audio('boden', ['assets/audio/bodenstaendig_2000_in_rock_4bit.mp3']);
21+
22+
}
23+
24+
var s;
25+
var music;
26+
27+
function create() {
28+
29+
game.world._stage.backgroundColorString = '#182d3b';
30+
31+
music = game.add.audio('boden');
32+
music.play();
33+
34+
s = game.add.sprite(game.world.centerX, game.world.centerY, 'disk');
35+
s.anchor.setTo(0.5, 0.5);
36+
37+
}
38+
39+
function update() {
40+
41+
s.rotation += 0.01;
42+
43+
}
44+
45+
function render() {
46+
47+
game.debug.renderSoundInfo(music, 20, 32);
48+
49+
}
50+
51+
})();
52+
53+
</script>
54+
55+
</body>
56+
</html>

src/core/Game.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Phaser.Game.prototype = {
295295
this.time = new Phaser.Time(this);
296296
this.tweens = new Phaser.TweenManager(this);
297297
this.input = new Phaser.Input(this);
298-
// this.sound = new Phaser.SoundManager(this);
298+
this.sound = new Phaser.SoundManager(this);
299299
// this.physics = new Phaser.Physics.PhysicsManager(this);
300300
this.plugins = new Phaser.PluginManager(this, this);
301301
this.net = new Phaser.Net(this);
@@ -379,7 +379,7 @@ Phaser.Game.prototype = {
379379
this.input.update();
380380
this.tweens.update();
381381
// this.stage.update();
382-
// this.sound.update();
382+
this.sound.update();
383383
// this.physics.update();
384384
this.world.update();
385385
this.state.update();

src/gameobjects/GameObjectFactory.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ Phaser.GameObjectFactory.prototype = {
4141

4242
return this.game.tweens.create(obj, localReference);
4343

44+
},
45+
46+
audio: function (key, volume, loop) {
47+
48+
volume = volume || 1;
49+
loop = loop || false;
50+
51+
return this.game.sound.add(key, volume, loop);
52+
4453
}
4554

55+
4656
};

0 commit comments

Comments
 (0)