Results 1 to 5 of 5

Thread: Can anyone answer this??

  1. #1

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228

    Question Can anyone answer this??

    Ok, I have a little animation program, but its doing something weird and I don't understand why:
    Code:
    final int LOOP = 100;
    ...
    Image [] images = new Image [54];  // thats the number of frames i have
    for( int i = 0; i < 54; i++ )
    {
        images[i] = new ImageIcon( SOME_PATH + SOME_FILENAME + i ).getImage();
    }
    ...
    for( int l = 0; l < LOOP; l++ )
    {
        for( int x = 0; x < 54; x++ )
        {
            fill( images[x], 0, 0 );
            render();
        }
    }
    ...
    fill() is a function that fills the image into a back buffer, and render fills the back buffer on to the screen.

    HERE's THE PROBLEM: When i run the program it starts out by painting frame( or image ) 1 to the screen, then goes blank, then 1, 2, blank... 1, 2, 3, blank... 1, 2, 3, 4, blank... and so on until its rendered all of them then it loops properly.... WHATS UP WITH THIS??
    To protect time is to protect everything...

  2. #2
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    I think your problem could be with your backbuffer. Instead of the fill and the render, try writing directly to the screen. That should work. If it doesn't then I'm

    It sounds like either your backbuffer proc or your render proc takes more than one image and then runs through it. It would conform to the loop. Another thing you can try is to run render AFTER you run the inner loop ie:
    Code:
    for( int l = 0; l < LOOP; l++ )
    {
        for( int x = 0; x < 54; x++ )
        {
            fill( images[x], 0, 0 );       
        }
        render();
    }
    The code you've given should work though.

  3. #3

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    It does work... eventually... Its just that the screen keeps going blank like ive said. I renders image 1, then blank. Image 1, 2, then blank. So on and so forth until all hase been rendered. That's when it loops properly. I am stumped.
    To protect time is to protect everything...

  4. #4
    Addicted Member Mrs Kensington's Avatar
    Join Date
    Sep 2001
    Location
    Dorset, UK
    Posts
    144
    are you sure the images have finished loading off the drive properly?

    Most methods to load Images (don't know about this one, haven't used it) load the image asynchronously... as in the method returns the pointer to the image but the image hasn't fully loaded yet. It then loads the image.

    You may want to look into the MediaTracker Object, you can add Images to it and then call a method that waits for all images to load properly.

    This should ensure that all images have been loaded properly.

    The code would look something like this...
    Code:
    Image [] images = new Image[54];
    MediaTracker mt = new MediaTracker();
    for(int i=0; i<54;i++)
    {
    &nbsp;&nbsp;&nbsp;&nbsp;images[i] = new ImageIcon(SOME_PATH + SOME_FILENAME + i).getImage();
    &nbsp;&nbsp;&nbsp;&nbsp;mt.addImage(images[i], 0);
    }
    
    mt.waitForID(o);
    tho with some exception handling as waitForID throws InterruptedException

    Hope that helps.

    Mrs K
    Ford? Theres an infinite number of monkeys outside that want to talk to you about a script of hamlet they've produced!

  5. #5

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    thanx, I'll look into that.
    To protect time is to protect everything...

Posting Permissions

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



Click Here to Expand Forum to Full Width