Content-Length: 551012 | pFad | http://github.com/CreateJS/SoundJS/commit/e10a583bfdcd0a867144a3139f1067a6cc14acae

06 Minor demo improvements · CreateJS/SoundJS@e10a583 · GitHub
Skip to content

Commit e10a583

Browse files
committed
Minor demo improvements
1 parent 0defb6a commit e10a583

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

examples/04_SoundTween.html

100644100755
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<header class="SoundJS">
1515
<h1>Sound Tween</h1>
1616

17-
<p>This example shows how to tween volume and pan. Note that HTML audio does not support panning.</p>
17+
<p>This example shows how to tween volume and pan. <b>Note that HTML audio does not support panning</b>.</p>
1818
</header>
1919

2020
<div class="content" id="content">
@@ -129,29 +129,33 @@ <h2>Sorry!</h2>
129129

130130
function initSoundTween() {
131131
setMessage("Volume Down: 0.0");
132-
tween = createjs.Tween.get(soundInstance, {loop: true})
132+
tween = createjs.Tween.get(soundInstance, {loop: true, onChange:handleSoundChange})
133133
.to({volume: 0.0}, 3 * baseTime)
134-
.wait(baseTime).call(setMessage, ["Volume Up: 0.5"])
134+
.wait(baseTime)
135135
.to({volume: 0.5}, 3 * baseTime)
136-
.wait(baseTime).call(setMessage, ["Volume Up: 1.0"])
136+
.wait(baseTime)
137137
.to({volume: 1.0}, 3 * baseTime)
138-
.wait(baseTime).call(setMessage, ["Volume Down: 0.5"])
138+
.wait(baseTime)
139139
.to({volume: 0.5}, 3 * baseTime)
140-
.wait(baseTime).call(setMessage, ["Pan Right: 1.0"])
140+
.wait(baseTime)
141141
.to({pan: 1}, 3 * baseTime)
142-
.wait(baseTime).call(setMessage, ["Pan Center: 0.0"])
142+
.wait(baseTime)
143143
.to({pan: 0}, 3 * baseTime)
144-
.wait(baseTime).call(setMessage, ["Pan Left: -1.0"])
144+
.wait(baseTime)
145145
.to({pan: -1}, 3 * baseTime)
146-
.wait(baseTime).call(setMessage, ["Pan Center: 0.0"])
146+
.wait(baseTime)
147147
.to({pan: 0}, 3 * baseTime)
148-
.wait(baseTime).call(setMessage, ["Volume Down: 0.0, Pan Left: -1.0"])
148+
.wait(baseTime)
149149
.to({pan: -1, volume: 0.0}, 3 * baseTime)
150-
.wait(baseTime).call(setMessage, ["Volume Up: 1.0, Pan Right: 1.0"])
150+
.wait(baseTime)
151151
.to({pan: 1, volume: 1}, 6 * baseTime)
152-
.wait(baseTime).call(setMessage, ["Volume Down: 0.5, Pan Center: 0.0"])
152+
.wait(baseTime)
153153
.to({pan: 0, volume: 0.5}, 3 * baseTime)
154-
.wait(baseTime).call(setMessage, ["Volume Down: 0.0"]);
154+
.wait(baseTime)
155+
}
156+
157+
function handleSoundChange() {
158+
setMessage("<b>Volume Up:" + soundInstance.volume.toFixed(2) +" Pan Right:" + soundInstance.pan.toFixed(2)) + "</b>";
155159
}
156160

157161
function setMessage(message) {

examples/05_AudioSprite.html

100644100755
Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ <h2>Sorry!</h2>
3333
<!-- We also provide hosted minified versions of all CreateJS libraries.
3434
http://code.createjs.com -->
3535

36+
<style>
37+
.red {
38+
color:red;
39+
font-size:large;
40+
}
41+
.blue {
42+
color:#0b93d5;
43+
font-size:small;
44+
}
45+
.orange {
46+
color:orange;
47+
font-size:xx-large;
48+
49+
}
50+
</style>
3651
<script id="editable">
3752
var displayMessage; // the HTML element we use to display messages to the user
3853

@@ -95,7 +110,11 @@ <h2>Sorry!</h2>
95110
return;
96111
}
97112

98-
this.sprite = ["pew", "hit", "explode"]; // this code is not needed for sprites, it is used for the looping effect
113+
this.sprite = [
114+
{id:"pew", class:"blue"},
115+
{id:"hit", class:"red"},
116+
{id:"explode", class:"orange"}
117+
]; // this code is not needed for sprites, it is used for the looping effect
99118
var assetsPath = "../_assets/audio/";
100119
var sounds = [
101120
// This is an audio sprite. The sprite property tells SoundJS what ids to use for playback, with time to start playback and length of playback
@@ -133,15 +152,18 @@ <h2>Sorry!</h2>
133152
this.currentStep = 0;
134153
this.loops = Math.floor((Math.random() * this.MAX_LOOPS)); // random between 0 and MAX_LOOPS -1
135154

136-
this.soundInstance = createjs.Sound.play(this.sprite[this.currentStep], {loop: this.loops});
155+
var spriteData = this.sprite[this.currentStep];
156+
157+
this.soundInstance = createjs.Sound.play(spriteData.id, {loop: this.loops});
137158
this.soundInstance.addEventListener("loop", this.loopProxy);
138159
this.soundInstance.addEventListener("complete", createjs.proxy(this.nextAudioRelay, this));
139-
this.displayStatus.innerHTML = this.sprite[this.currentStep];
160+
this.displayStatus.innerHTML = '<div class='+spriteData.class+'>'+spriteData.id+'</div>';
140161
},
141162

142163
// update display text
143164
handleLoop: function () {
144-
this.displayStatus.innerHTML = this.displayStatus.innerHTML + " " + this.sprite[this.currentStep];
165+
var spriteData = this.sprite[this.currentStep];
166+
this.displayStatus.innerHTML = this.displayStatus.innerHTML + " " + '<div id="effect" class='+spriteData.class+'>'+spriteData.id+'</div>';
145167
},
146168

147169
// kick off delayed next step of audio loop
@@ -152,16 +174,19 @@ <h2>Sorry!</h2>
152174

153175
delayedNextAudio: function () {
154176
this.currentStep++;
155-
this.soundInstance = createjs.Sound.play(this.sprite[this.currentStep], {loop: this.loops});
177+
178+
var spriteData = this.sprite[this.currentStep];
179+
180+
this.soundInstance = createjs.Sound.play(spriteData.id, {loop: this.loops});
156181
this.soundInstance.addEventListener("loop", this.loopProxy);
157182
this.soundInstance.addEventListener("complete", createjs.proxy(this.handleFinalAudio, this));
158-
this.displayStatus.innerHTML = this.sprite[this.currentStep];
183+
this.displayStatus.innerHTML = '<div class='+spriteData.class+'>'+spriteData.id+'</div>';
159184
},
160185

161186
// final step of audio loop
162187
handleFinalAudio: function () {
163188
this.currentStep++;
164-
this.soundInstance = createjs.Sound.play(this.sprite[this.currentStep]);
189+
this.soundInstance = createjs.Sound.play(this.sprite[this.currentStep].id);
165190
this.soundInstance.addEventListener("complete", createjs.proxy(this.nextAudioRelay, this));
166191
this.handleLoop();
167192

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/CreateJS/SoundJS/commit/e10a583bfdcd0a867144a3139f1067a6cc14acae

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy