@@ -33,6 +33,21 @@ <h2>Sorry!</h2>
33
33
<!-- We also provide hosted minified versions of all CreateJS libraries.
34
34
http://code.createjs.com -->
35
35
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 >
36
51
< script id ="editable ">
37
52
var displayMessage ; // the HTML element we use to display messages to the user
38
53
@@ -95,7 +110,11 @@ <h2>Sorry!</h2>
95
110
return ;
96
111
}
97
112
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
99
118
var assetsPath = "../_assets/audio/" ;
100
119
var sounds = [
101
120
// 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>
133
152
this . currentStep = 0 ;
134
153
this . loops = Math . floor ( ( Math . random ( ) * this . MAX_LOOPS ) ) ; // random between 0 and MAX_LOOPS -1
135
154
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 } ) ;
137
158
this . soundInstance . addEventListener ( "loop" , this . loopProxy ) ;
138
159
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>' ;
140
161
} ,
141
162
142
163
// update display text
143
164
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>' ;
145
167
} ,
146
168
147
169
// kick off delayed next step of audio loop
@@ -152,16 +174,19 @@ <h2>Sorry!</h2>
152
174
153
175
delayedNextAudio : function ( ) {
154
176
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 } ) ;
156
181
this . soundInstance . addEventListener ( "loop" , this . loopProxy ) ;
157
182
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>' ;
159
184
} ,
160
185
161
186
// final step of audio loop
162
187
handleFinalAudio : function ( ) {
163
188
this . currentStep ++ ;
164
- this . soundInstance = createjs . Sound . play ( this . sprite [ this . currentStep ] ) ;
189
+ this . soundInstance = createjs . Sound . play ( this . sprite [ this . currentStep ] . id ) ;
165
190
this . soundInstance . addEventListener ( "complete" , createjs . proxy ( this . nextAudioRelay , this ) ) ;
166
191
this . handleLoop ( ) ;
167
192
0 commit comments