Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:Is there a better way to do this




On Feb 10, 2008, at 12:04 PM, robert engels wrote:

A very easy, and efficient way to do animation is to use a Swing
Timer. Have it fire as often as the number of frames per second that
you desire.

Disable double buffering on the component.

In the Timer action event call repaint() on the component.

Have another thread build the frames as BufferedImages, normally it
should be building at least a few frames ahead - i.e. buffering the
frames as well.

In the paintComponent(), call drawImage() using the desired frame of
the pre-built buffered image. If the frame is not yet available, then
you cannot sustain the requested rate, probably just skip drawing
that frame, and hope by the next paintComponent the next desired
frame is available.

You don't need the other thread building buffered images if the
amount of work done in paintComponent() is kept to a minimum - you
can do "live" animation.

The OS (especially OSX) will do (in many cases) double buffering that
you cannot easily disable


Thanks for this advice. It might be the technique I was looking for.
Would this work well for a slideshow of large jpg's with fade-ins and fade-outs?
I am already seeing large memory requirements, would this boost that significantly also?




pjpfeiffer


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.