@@ -11,6 +11,9 @@ module Phaser {
1111
1212 export class Cache {
1313
14+ /**
15+ * Cache constructor
16+ */
1417 constructor ( game : Game ) {
1518
1619 this . _game = game ;
@@ -22,58 +25,128 @@ module Phaser {
2225
2326 }
2427
28+ /**
29+ * Local private reference to game.
30+ */
2531 private _game : Game ;
2632
33+ /**
34+ * Canvas key-value container.
35+ * @type {object }
36+ */
2737 private _canvases ;
38+ /**
39+ * Image key-value container.
40+ * @type {object }
41+ */
2842 private _images ;
43+ /**
44+ * Sound key-value container.
45+ * @type {object }
46+ */
2947 private _sounds ;
48+ /**
49+ * Text key-value container.
50+ * @type {object }
51+ */
3052 private _text ;
3153
54+ /**
55+ * Add a new canvas.
56+ * @param key Asset key for this canvas.
57+ * @param canvas Canvas DOM element.
58+ * @param context Render context of this canvas.
59+ */
3260 public addCanvas ( key : string , canvas : HTMLCanvasElement , context : CanvasRenderingContext2D ) {
3361
3462 this . _canvases [ key ] = { canvas : canvas , context : context } ;
3563
3664 }
3765
66+ /**
67+ * Add a new sprite sheet.
68+ * @param key Asset key for the sprite sheet.
69+ * @param url URL of this sprite sheet file.
70+ * @param data Extra sprite sheet data.
71+ * @param frameWidth Width of the sprite sheet.
72+ * @param frameHeight Height of the sprite sheet.
73+ * @param frameMax How many frames stored in the sprite sheet.
74+ */
3875 public addSpriteSheet ( key : string , url : string , data , frameWidth : number , frameHeight : number , frameMax : number ) {
3976
4077 this . _images [ key ] = { url : url , data : data , spriteSheet : true , frameWidth : frameWidth , frameHeight : frameHeight } ;
4178 this . _images [ key ] . frameData = AnimationLoader . parseSpriteSheet ( this . _game , key , frameWidth , frameHeight , frameMax ) ;
4279
4380 }
4481
82+ /**
83+ * Add a new texture atlas.
84+ * @param key Asset key for the texture atlas.
85+ * @param url URL of this texture atlas file.
86+ * @param data Extra texture atlas data.
87+ * @param data Texture atlas frames data.
88+ */
4589 public addTextureAtlas ( key : string , url : string , data , jsonData ) {
4690
4791 this . _images [ key ] = { url : url , data : data , spriteSheet : true } ;
4892 this . _images [ key ] . frameData = AnimationLoader . parseJSONData ( this . _game , jsonData ) ;
4993
5094 }
5195
96+ /**
97+ * Add a new image.
98+ * @param key Asset key for the image.
99+ * @param url URL of this image file.
100+ * @param data Extra image data.
101+ */
52102 public addImage ( key : string , url : string , data ) {
53103
54104 this . _images [ key ] = { url : url , data : data , spriteSheet : false } ;
55105
56106 }
57107
108+ /**
109+ * Add a new sound.
110+ * @param key Asset key for the sound.
111+ * @param url URL of this sound file.
112+ * @param data Extra sound data.
113+ */
58114 public addSound ( key : string , url : string , data ) {
59115
60116 this . _sounds [ key ] = { url : url , data : data , decoded : false } ;
61117
62118 }
63119
120+ /**
121+ * Add a new decoded sound.
122+ * @param key Asset key for the sound.
123+ * @param url URL of this sound file.
124+ * @param data Extra sound data.
125+ */
64126 public decodedSound ( key : string , data ) {
65127
66128 this . _sounds [ key ] . data = data ;
67129 this . _sounds [ key ] . decoded = true ;
68130
69131 }
70132
133+ /**
134+ * Add a new text data.
135+ * @param key Asset key for the text data.
136+ * @param url URL of this text data file.
137+ * @param data Extra text data.
138+ */
71139 public addText ( key : string , url : string , data ) {
72140
73141 this . _text [ key ] = { url : url , data : data } ;
74142
75143 }
76144
145+ /**
146+ * Get canvas by key.
147+ * @param key Asset key of the canvas you want.
148+ * @return {object } The canvas you want.
149+ */
77150 public getCanvas ( key : string ) {
78151
79152 if ( this . _canvases [ key ] )
@@ -85,6 +158,11 @@ module Phaser {
85158
86159 }
87160
161+ /**
162+ * Get image data by key.
163+ * @param key Asset key of the image you want.
164+ * @return {object } The image data you want.
165+ */
88166 public getImage ( key : string ) {
89167
90168 if ( this . _images [ key ] )
@@ -96,6 +174,11 @@ module Phaser {
96174
97175 }
98176
177+ /**
178+ * Get frame data by key.
179+ * @param key Asset key of the frame data you want.
180+ * @return {object } The frame data you want.
181+ */
99182 public getFrameData ( key : string ) : FrameData {
100183
101184 if ( this . _images [ key ] && this . _images [ key ] . spriteSheet == true )
@@ -107,6 +190,11 @@ module Phaser {
107190
108191 }
109192
193+ /**
194+ * Get sound data by key.
195+ * @param key Asset key of the sound you want.
196+ * @return {object } The sound data you want.
197+ */
110198 public getSound ( key : string ) {
111199
112200 if ( this . _sounds [ key ] )
@@ -118,6 +206,11 @@ module Phaser {
118206
119207 }
120208
209+ /**
210+ * Check whether an asset is decoded sound.
211+ * @param key Asset key of the sound you want.
212+ * @return {object } The sound data you want.
213+ */
121214 public isSoundDecoded ( key : string ) : bool {
122215
123216 if ( this . _sounds [ key ] )
@@ -127,6 +220,11 @@ module Phaser {
127220
128221 }
129222
223+ /**
224+ * Check whether an asset is sprite sheet.
225+ * @param key Asset key of the sprite sheet you want.
226+ * @return {object } The sprite sheet data you want.
227+ */
130228 public isSpriteSheet ( key : string ) : bool {
131229
132230 if ( this . _images [ key ] )
@@ -136,6 +234,11 @@ module Phaser {
136234
137235 }
138236
237+ /**
238+ * Get text data by key.
239+ * @param key Asset key of the text data you want.
240+ * @return {object } The text data you want.
241+ */
139242 public getText ( key : string ) {
140243
141244 if ( this . _text [ key ] )
@@ -147,6 +250,9 @@ module Phaser {
147250
148251 }
149252
253+ /**
254+ * Clean up cache memory.
255+ */
150256 public destroy ( ) {
151257
152258 for ( var item in this . _canvases )
0 commit comments