Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Posts
    439
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation preload my images

    I have this game
    http://www.geocities.com/alaios2/match/
    i want to preload all the images before the player can do any selection....What can i do?

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Uhhh, maybe adding this will do it
    Code:
            for (var t = 1; t <= tiles; t++) {
              tile[((s-1)*tiles)+t] = new Image()
              tile[((s-1)*tiles)+t].src = 'images/'+s+'_'+t+'.gif';
            }

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Posts
    439
    Thanks
    3
    Thanked 0 Times in 0 Posts

    nah!!

    xmmm no thankes..this does not work as i want....

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try creating an array of the images in your head tag and running through them, as a function, and call that function in your body tag

    <body onload="preloadimages();">

    It should preload the images, just take a longer time to open the page initially.

    Duniyadnd

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Try changing:

    var notloaded=true;

    ..to:

    var unloaded=0;

    Then:

    unloaded = tiles * sets + 1;
    for (var t = 1; t <= tiles; t++) {
    tile[((s-1)*tiles)+t] = new Image();
    tile[((s-1)*tiles)+t].onload = function() {--unloaded};
    tile[((s-1)*tiles)+t].src = 'images/'+s+'_'+t+'.gif';
    }

    Then:

    function select(pos) {
    if (unloaded) return;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •