Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

hopefully fixed loading

  • Loading branch information...
commit fb94ef0e70094c219e605c1282f84bb67ed0c931 1 parent aa6c0c2
@BlackScorp authored
Showing with 31 additions and 21 deletions.
  1. +1 −0  .gitignore
  2. +27 −19 assets/js/crafty.js
  3. +3 −2 assets/js/levels.js
View
1  .gitignore
@@ -2,3 +2,4 @@
/assets/img/.fr-5KubhJ/
/nbproject
.*.sw?
+*~
View
46 assets/js/crafty.js
@@ -7206,21 +7206,27 @@ Crafty.c("Text", {
*/
load: function (data, oncomplete, onprogress, onerror) {
- var i = 0, l = data.length, current, obj, total = l, j = 0, ext = "",event;
+ var i = 0, l = data.length, current, obj, total = l, j = 0, ext = "",event,canplay;
for (; i < l; ++i) {
- obj = new Object();
+
current = data[i];
- console.log(current);
+ event = '';
+ obj ={};
ext = current.substr(current.lastIndexOf('.') + 1).toLowerCase();
if (Crafty.support.audio && (ext === "mp3" || ext === "wav" || ext === "ogg" || ext === "mp4")) {
obj = new Audio(current);
- event = 'canplaythrough';
- //event = 'play';
- this.assets[current] = obj;
+ event = 'loadstart';
+ canplay = obj.canPlayType(Crafty.audio.type[ext]);
+ if(canplay !== "" && canplay !== "no"){
+ this.assets[current] = obj;
+ }else{
+ j--;
+ delete obj;
+ }
//Chrome doesn't trigger onload on audio, see http://code.google.com/p/chromium/issues/detail?id=77794
if (navigator.userAgent.indexOf('Chrome') != -1) j++;
} else if (ext === "jpg" || ext === "jpeg" || ext === "gif" || ext === "png") {
@@ -7232,36 +7238,38 @@ Crafty.c("Text", {
total--;
continue; //skip if not applicable
}
-
- function progress(){
+ //Progress function
+ function pro(){
++j;
//if progress callback, give information of assets loaded, total and percent
if (onprogress)
- onprogress.call(this, {loaded: j, total: total, percent: (j / total * 100),obj:this});
- console.log(this);
-
+ onprogress({loaded: j, total: total, percent: (j / total * 100),obj:this});
+
if(j === total && oncomplete) oncomplete();
};
-
- function error(){
+ //Error function
+ function err(){
if (onerror)
- onerror.call(this, {loaded: j, total: total, percent: (j / total * 100),obj:this});
+ onerror({loaded: j, total: total, percent: (j / total * 100),obj:this});
j++;
if(j === total && oncomplete) oncomplete();
};
+
if (obj.attachEvent) { //IE
- obj.attachEvent('on' + event, progress);
- obj.attachEvent('onerror', error);
+
+ obj.attachEvent('on' + event, pro);
+ obj.attachEvent('onerror', err);
} else { //Everyone else
- obj.addEventListener(event, progress, false);
- obj.addEventListener('error', error, false);
+ obj.addEventListener(event, pro, false);
+ obj.addEventListener('error', err, false);
}
}
-
+
+
},
/**@
* #Crafty.modules
View
5 assets/js/levels.js
@@ -7,7 +7,7 @@ Crafty.scene("Loading",function(){
for(var i in Crafty.assets){
toLoad.push(i);
}
-
+
//Setup background image
Crafty.background("url("+game_path+"assets/img/loading.jpg) black");
@@ -51,8 +51,9 @@ Crafty.scene("Loading",function(){
},
function(e) {
+
//uh oh, error loading
- console.log("Error on loading: "+e.src);
+ console.log("Error on loading: "+e.obj.src);
}
);
Please sign in to comment.
Something went wrong with that request. Please try again.