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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Location
    SC, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Need to speed up swapping of pre-loaded images.

    I'm currently trying to write a version of the game Memory with JavaScript. Functionaly speaking I've got it down pat, but when a player clicks on a card to flip it over there's about a 2 or 3 second delay before it happens. I already have the images pre-loaded (unless there's an error I'm unaware of). Anyone have any ideas how I might be able to speed the image swaps up? When running the html file straight from my hard drive everything works perfectly, perhaps I'm just doomed to be limited by my bandwidth.

    JavaScript directly involved with image swapping:
    --------------------------------------------------------------------------
    // Array of card images
    imageArray = new Array();
    var ImageNum = 0;
    var image_dir = ""
    imageArray[ImageNum++] = new imageItem(image_dir + "zero.jpg");
    imageArray[ImageNum++] = new imageItem(image_dir + "one.jpg");
    imageArray[ImageNum++] = new imageItem(image_dir + "two.jpg");
    imageArray[ImageNum++] = new imageItem(image_dir + "three.jpg");
    imageArray[ImageNum++] = new imageItem(image_dir + "four.jpg");
    imageArray[ImageNum++] = new imageItem(image_dir + "five.jpg");
    imageArray[ImageNum++] = new imageItem(image_dir + "six.jpg");
    imageArray[ImageNum++] = new imageItem(image_dir + "seven.jpg");
    imageArray[ImageNum++] = new imageItem(image_dir + "eight.jpg");
    imageArray[ImageNum++] = new imageItem(image_dir + "nine.jpg");
    imageArray[ImageNum++] = new imageItem(image_dir + "card_back.jpg");

    function imageItem(image_location) {
    this.image_item = new Image(50, 50);
    this.image_item.src = image_location;
    }

    function get_ImageItemLocation(imageObj) {
    return(imageObj.image_item.src)
    }

    // flips selected card
    function flip(cell){
    var row;
    var col;

    if(document[cell].src == get_ImageItemLocation(imageArray[10])){
    // imageArray[10] = "card_back.jpg"
    var rc = cell_to_rc(cell); // cell name to row and column
    row = rc[0];
    col = rc[1];
    var temp = grid[row][col][0];
    document[cell].src = get_ImageItemLocation(imageArray[temp]);
    }
    else {
    document[cell].src = "card_back.jpg";
    }
    }
    --------------------------------------------------------------------------

    For the complete file goto: http://www.clemson.edu/~csencsm/game...ry/memory.html

    Thanks
    (\/)att

  • #2
    Regular Coder oldcrazylegs's Avatar
    Join Date
    Feb 2004
    Location
    East Moline Illinois USA
    Posts
    415
    Thanks
    4
    Thanked 5 Times in 4 Posts
    I read somewhere that you can't preload images with Internet Explorer.

  • #3
    New to the CF scene
    Join Date
    May 2004
    Location
    SC, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Well that would definately suck. I think I may have figured out a way around it this morning though. I'm thinking about instead of swapping images I'll have both of them there and just change either the visibility or the z-index of the pictures.
    (\/)att


  •  

    Posting Permissions

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