Skip to main content

Frame Accurate Animation

7 replies [Last post]
francoislionet
Offline
Joined: 2008-01-13

Hello all,

When my application is loading images and sounds from the disc, I would like to display a FrameAccurateAnimation, more precisely an Image Frame Accurate Animation. This animation is to run on its own while the data is loading.
OK I found the info on the classes, but, as I do not have the specs right now (I have ordered them, but they will come in about a month), I am a bit stuck.

In the JavaDoc about FrameAccurateAnimation, I cant find anywhere where I tell the object the images to display. There must be someplace where I send the list of images! But I cant find it!

Can anyone help me?

Thanks in advance, Francois

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
clinic
Offline
Joined: 2008-02-14

I am not super well versed in Frame Accurate Animation... but I am wondering, if all you are showing is a loading animation, why you need it to be done using the Frame Accurate Animaiton framework?

Why not load a small grin script, then begin your data load?

dbreitenfeld
Offline
Joined: 2007-03-18

Hi francoislionet,

The "loading" of your assets does this include reading from the disc? If so then using frame accurate animation (relying on the playback of the video on the disc) and reading from the disc at the same time can cause playback issues and could counter act the using of frame accurate animation, thus you might actually get better performance using Direct Draw animation instead.

However that does not answer your question. So below is some example code (please use as an example and not sample code, its purpose is to give you the steps that need to be done) that might answer your question.

Hope this helps,

Denny B.
------------------------------------------------------------------------------------------------------------
[i]NetBlender DoStudio MX Team - NDS - http://dostudio.netblender.com[/i]

dbreitenfeld
Offline
Joined: 2007-03-18

/**
  * you need to determin how you would like to have this list images obtained. If you are just moving an image t
hat is different.
 */
Image[] frames = null;

int numberOfFramesToBuffer = 1; //Good number to use to keep memory usage low
AnimationParameters params = new AnimationParameters();

SyncFrameAccurateAnimation synch = SyncFrameAccurateAnimation.getInstance(new Dimension(1920, 1080) , numberOfFramesToBuffer, params);

//Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height.
synch.setBounds(860, 440, 200, 200);

//Add the synch object to the HScene object before doing the try catch block
try
{
     int frameCount = 30;
     int currentFrame = 0;
     int repeatCount = 0;
     Graphics screen = null;
     while (repeatCount < 6) //six was randomly picked add your own logic here.
     {
          if (currentFrame == 30) {
            currentFrame = 0;
            repeatCount++;
          }
          screen = synch.startDrawing(currentFrame);
          screen.drawImage(frames[currentFrame], 0, 0, null);
          synch.finishDrawing(currentFrame);
          currentFrame++;
     }
}
catch(Exception ex)
{
     ex.printStackTrace();
}
finally{
     //Remove the synch object from the HScene object before doing the try catch block
}

Message was edited by: dbreitenfeld

francoislionet
Offline
Joined: 2008-01-13

Thanks Dennis (it is you name isn't it)? Thanks for being so nice and helpfull.

My plan is to first load the pictures of the waiting animation (small images, like four 128x128 pixels images), start the animation, and then load the actual pictures of the games, then stop the animation when the load is complete.

But there are several things I do not understand in your example.

At no place in the code, you actually tell the system where to find the graphics. You do state a Image array, call "frames", but you do not use it in your code. Have you forgotten something in the example?

And, I thought (from what I learned in Barcelona) that FrameAccurateAnimation was something handled automatically by the player, and you could actually perform other things while the animation is playing.
In your example, you have a loop that actually performs the animation. So I think I was wrong. Do you think I can launch a thread to do the animation while loading other graphics?

I have a bottle of champagne ready for you at the end of my project to thank you for all your help!

Francois

dbreitenfeld
Offline
Joined: 2007-03-18

Hi Francois,

I'm glad to be of some help and my name amazingly enough is just Denny.

Thanks for the update on how you wish to use the animation. With this new information I have provided you with the wrong approach in my previous post. However before I provide the new answer let me answer your previous questions:

> At no place in the code, you actually tell the system where to find the graphics.
I left this up to you. You can load the images from the .jar file from the VFS, or maybe even the network someday So I did not say how to do this i just assumed that you would load them in the method you choose then store them in an Array called frames.

> You do state a Image array, call "frames", but you do not use it in your code.
Unfortunately it is hard to say which line number this line is on but the line in which I use the array is here: screen.drawImage(frames[currentFrame], 0, 0, null); On my screen this looks like line 25 in the example code above.

> Do you think I can launch a thread to do the animation while loading other graphics?
Yes you can do this but on older machines you might not get the performance you would like.

Ok instead of using the SyncFrameAccurateAnimation you will want to use ImageFrameAccurateAnimation class.

Here is an example of using the ImageFrameAccurateAnimation class (please use as example and not sample)

Image[] frames; //again you decide how to preload these images.
AnimationParameters params = new AnimationParameters();
params.threadPriority = Thread.MIN_PRIORITY;
ImageFrameAccurateAnimation sequence = null;
try{
     sequence = ImageFrameAccurateAnimation.getInstance(frames, new Dimension(128,128), params, ImageFrameAccurateAnimation.PLAY_REPEATING);
     //Add the sequence to the HSceen object here
     sequence.prepareImages();
     sequence.start();
}catch(Exception ex)
{
     ex.printStackTrace();
}
finally{
     if (sequence != null)
          //Remove the sequence from the HSceen object here.
}

We have not used this class so I am just providing you with the "text" book approach. Maybe someone here has used it and knows of some tweaks that you might need to do?

Good Luck!

Denny B.
------------------------------------------------------------------------------------------------------------
[i]NetBlender DoStudio MX Team - NDS - http://dostudio.netblender.com[/i]

francoislionet
Offline
Joined: 2008-01-13

Hi Denny,

Silly me, I skipped over the line wher you actually draws the image on the screen. This is me, I am very bad at inspecting code (but good at debugging!).
Thank you for the new method of displaying the animation. I will try it soon, and report back here if it works. It could be of some help to other people.

francoislionet
Offline
Joined: 2008-01-13

I looked at my notes from the Barcelona conference, and I found what Mark Johnson said about Frame Accurate Animation. He said that it was badly implemented on some players. Kindof scary statement.
So to be on the safe side, I decided to use a simple method of creating a thread with the animation loop. It works very well (except that the animation stalls sometimes when the player is loading data, but I guess there is nothing that can be done against it).