Jump to content

(Pre)loading Assets


sima
 Share

Recommended Posts

I'm looking for the best way to ensure, that all required assets (images and audio) are ready to use, before I allow people to play.

 

I've tested several things, but they don't work reliably:
First try, DOM-preloading:

I created an empty <div> and filled it with assets:

<div id='id_memory' style='visibility: hidden;'></div>
// images:var preload_this = g_preload_image.pop();document.getElementById("id_memory").innerHTML += "<img height=1 width=1 src='"+preload_this+"'>";// audio:var preload_this_audio = g_preload_sound.pop();document.getElementById("id_memory").innerHTML += "<audio id='id_preload_"+g_preload_counter+"'></audio>";document.getElementById("id_preload_"+g_preload_counter).src="audio/"+preload_this_audio+".wav";document.getElementById("id_preload_"+g_preload_counter).volume = 0;document.getElementById("id_preload_"+g_preload_counter).play();document.getElementById("id_preload_"+g_preload_counter).pause();

This works for Firefox and IE afaik, but the image-preloading doesn't seem to work for Chrome and I'm not sure, if the audio-preload works at all...
Question: Is there an event that fires, when a <img>-tag or <audio>-tag finished loading? I tried <audio>-tag-ID.onload but that never fired.

My second try used a javascript image_object:

var preload_this = g_preload_image.pop();var img_obj = new Image();img_obj.src = preload_this;g_preloaded_images.push(img_obj);

This worked noticeably worse than the first method (on firefox, chrome and IE).

 

My third try is to ask you: How do you preload? How do you ensure, that all assets are ready to use?

 

EDIT:
Does anyone have experience with Preload.js ( http://www.createjs.com/#!/PreloadJS )? Is it worth using?

 

Thanks in advance,

Sima

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...