|
-
Nov 5th, 2002, 12:06 PM
#1
Thread Starter
Addicted Member
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...
-
Nov 5th, 2002, 02:24 PM
#2
Hyperactive Member
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.
-
Nov 5th, 2002, 03:23 PM
#3
Thread Starter
Addicted Member
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...
-
Nov 5th, 2002, 04:54 PM
#4
Addicted Member
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++)
{
images[i] = new ImageIcon(SOME_PATH + SOME_FILENAME + i).getImage();
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!
-
Nov 10th, 2002, 11:28 PM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|