@@ -1283,6 +1283,16 @@ Phaser.Loader.prototype = {
12831283
12841284 } ,
12851285
1286+ /**
1287+ * Transforms the asset URL. The default implementation prepends the baseURL.
1288+ *
1289+ * @method Phaser.Loader#transformUrl
1290+ * @protected
1291+ */
1292+ transformUrl : function ( url , file ) {
1293+ return this . baseURL + url ;
1294+ } ,
1295+
12861296 /**
12871297 * Start fetching a resource.
12881298 *
@@ -1294,13 +1304,11 @@ Phaser.Loader.prototype = {
12941304 */
12951305 loadFile : function ( file ) {
12961306
1297- var _this = this ;
1298-
12991307 // Image or Data?
13001308 switch ( file . type )
13011309 {
13021310 case 'packfile' :
1303- this . xhrLoad ( file , this . baseURL + file . url , 'text' , this . fileComplete ) ;
1311+ this . xhrLoad ( file , this . transformUrl ( file . url , file ) , 'text' , this . fileComplete ) ;
13041312 break ;
13051313
13061314 case 'image' :
@@ -1318,7 +1326,7 @@ Phaser.Loader.prototype = {
13181326 // WebAudio or Audio Tag?
13191327 if ( this . game . sound . usingWebAudio )
13201328 {
1321- this . xhrLoad ( file , this . baseURL + file . url , 'arraybuffer' , this . fileComplete ) ;
1329+ this . xhrLoad ( file , this . transformUrl ( file . url , file ) , 'arraybuffer' , this . fileComplete ) ;
13221330 }
13231331 else if ( this . game . sound . usingAudioTag )
13241332 {
@@ -1329,36 +1337,34 @@ Phaser.Loader.prototype = {
13291337 {
13301338 this . fileError ( file , null , 'no supported audio URL specified' ) ;
13311339 }
1332-
13331340 break ;
13341341
13351342 case 'json' :
13361343
13371344 if ( this . useXDomainRequest && window . XDomainRequest )
13381345 {
1339- this . xhrLoadWithXDR ( file , this . baseURL + file . url , 'text' , this . jsonLoadComplete ) ;
1346+ this . xhrLoadWithXDR ( file , this . transformUrl ( file . url , file ) , 'text' , this . jsonLoadComplete ) ;
13401347 }
13411348 else
13421349 {
1343- this . xhrLoad ( file , this . baseURL + file . url , 'text' , this . jsonLoadComplete ) ;
1350+ this . xhrLoad ( file , this . transformUrl ( file . url , file ) , 'text' , this . jsonLoadComplete ) ;
13441351 }
1345-
13461352 break ;
13471353
13481354 case 'xml' :
13491355
1350- this . xhrLoad ( file , this . baseURL + file . url , 'text' , this . xmlLoadComplete ) ;
1356+ this . xhrLoad ( file , this . transformUrl ( file . url , file ) , 'text' , this . xmlLoadComplete ) ;
13511357 break ;
13521358
13531359 case 'tilemap' :
13541360
13551361 if ( file . format === Phaser . Tilemap . TILED_JSON )
13561362 {
1357- this . xhrLoad ( file , this . baseURL + file . url , 'text' , this . jsonLoadComplete ) ;
1363+ this . xhrLoad ( file , this . transformUrl ( file . url , file ) , 'text' , this . jsonLoadComplete ) ;
13581364 }
13591365 else if ( file . format === Phaser . Tilemap . CSV )
13601366 {
1361- this . xhrLoad ( file , this . baseURL + file . url , 'text' , this . csvLoadComplete ) ;
1367+ this . xhrLoad ( file , this . transformUrl ( file . url , file ) , 'text' , this . csvLoadComplete ) ;
13621368 }
13631369 else
13641370 {
@@ -1369,11 +1375,11 @@ Phaser.Loader.prototype = {
13691375 case 'text' :
13701376 case 'script' :
13711377 case 'physics' :
1372- this . xhrLoad ( file , this . baseURL + file . url , 'text' , this . fileComplete ) ;
1378+ this . xhrLoad ( file , this . transformUrl ( file . url , file ) , 'text' , this . fileComplete ) ;
13731379 break ;
13741380
13751381 case 'binary' :
1376- this . xhrLoad ( file , this . baseURL + file . url , 'arraybuffer' , this . fileComplete ) ;
1382+ this . xhrLoad ( file , this . transformUrl ( file . url , file ) , 'arraybuffer' , this . fileComplete ) ;
13771383 break ;
13781384 }
13791385
@@ -1385,6 +1391,8 @@ Phaser.Loader.prototype = {
13851391 */
13861392 loadImageTag : function ( file ) {
13871393
1394+ var _this = this ;
1395+
13881396 file . data = new Image ( ) ;
13891397 file . data . name = file . key ;
13901398
@@ -1410,7 +1418,7 @@ Phaser.Loader.prototype = {
14101418 }
14111419 } ;
14121420
1413- file . data . src = this . baseURL + file . url ;
1421+ file . data . src = this . transformUrl ( file . url , file ) ;
14141422
14151423 // Image is immediately-available/cached
14161424 if ( file . data . complete && file . data . width && file . data . height )
@@ -1428,13 +1436,15 @@ Phaser.Loader.prototype = {
14281436 */
14291437 loadAudioTag : function ( file ) {
14301438
1439+ var _this = this ;
1440+
14311441 if ( this . game . sound . touchLocked )
14321442 {
14331443 // If audio is locked we can't do this yet, so need to queue this load request. Bum.
14341444 file . data = new Audio ( ) ;
14351445 file . data . name = file . key ;
14361446 file . data . preload = 'auto' ;
1437- file . data . src = this . baseURL + file . url ;
1447+ file . data . src = this . transformUrl ( file . url , file ) ;
14381448
14391449 this . fileComplete ( file ) ;
14401450 }
@@ -1456,7 +1466,7 @@ Phaser.Loader.prototype = {
14561466 } ;
14571467
14581468 file . data . preload = 'auto' ;
1459- file . data . src = this . baseURL + file . url ;
1469+ file . data . src = this . transformUrl ( file . url , file ) ;
14601470 file . data . addEventListener ( 'canplaythrough' , playThroughEvent , false ) ;
14611471 file . data . load ( ) ;
14621472 }
@@ -1672,11 +1682,11 @@ Phaser.Loader.prototype = {
16721682
16731683 if ( file . format == Phaser . Loader . TEXTURE_ATLAS_JSON_ARRAY || file . format == Phaser . Loader . TEXTURE_ATLAS_JSON_HASH )
16741684 {
1675- this . xhrLoad ( file , this . baseURL + file . atlasURL , 'text' , this . jsonLoadComplete ) ;
1685+ this . xhrLoad ( file , this . transformUrl ( file . atlasURL , file ) , 'text' , this . jsonLoadComplete ) ;
16761686 }
16771687 else if ( file . format == Phaser . Loader . TEXTURE_ATLAS_XML_STARLING )
16781688 {
1679- this . xhrLoad ( file , this . baseURL + file . atlasURL , 'text' , this . xmlLoadComplete ) ;
1689+ this . xhrLoad ( file , this . transformUrl ( file . atlasURL , file ) , 'text' , this . xmlLoadComplete ) ;
16801690 }
16811691 else
16821692 {
@@ -1695,7 +1705,7 @@ Phaser.Loader.prototype = {
16951705 {
16961706 // Load the XML before carrying on with the next file
16971707 loadNext = false ;
1698- this . xhrLoad ( file , this . baseURL + file . xmlURL , 'text' , this . xmlLoadComplete ) ;
1708+ this . xhrLoad ( file , this . transformUrl ( file . xmlURL , file ) , 'text' , this . xmlLoadComplete ) ;
16991709 }
17001710 break ;
17011711
0 commit comments