Skip to main content

2 key hits

1 reply [Last post]
lgranie
Offline
Joined: 2006-04-29

Hi there,

I would like to write a carousel (like this one from blog of bug http://www.blogofbug.com/demonstrations/) in OpenGL. I am using Jogl and the Timing Framework.

Next, is the code of my turn() method. This method is called when the user press the left (direction = -1) or right(direction = 1) arrow key:
private void turn(int direction) {
if(animator.isRunning()) return;

int currentIndex = items.indexOf(currentItem);
final int index = (items.size() + (currentIndex - direction)) % items.size();

animator = PropertySetter.createAnimator(1500, this, "angle", angle, angle + (direction * Math.PI * 2 / items.size()));
animator.setAcceleration(0.5f);
animator.setDeceleration(0.3f);

animator.start();

animator.addTarget(new TimingTargetAdapter() {
public void end() {
currentItem = items.get(index);
}
});
}

As you can see, this method starts with a test. So, the user must wait the end of a move to do the next one. But I want that the user can press twice (or more) a key to go directly to the second (or more) element in my carousel.

I try to use thread synchronization but it generates a none thread owner exception. Apparently is common mistake when you mixe AWT and OpenGL.

Is it possible to interact with a running Animator to change the end value?

If you want the whole code you can find it at :
http://ambiance.googlecode.com/svn/trunk/ambiance-desktop/

Thanks,
Laurent.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
chet
Offline
Joined: 2003-08-07

Hi Laurent,

I'm not sure I'm following everything, but calling stop() on an Animator should result in the end() method of its TimingTargets being called. So if you want to stop one Animator early, and you want end() called, call stop(). (If you want to stop an Animator without its calling the end() event, call cancel()).

Chet.