/** Jump to a specific location (in frames). if the frame does not exist, go to last frame */ public void jump(int where) { if (frames.length > where) { currentFrame = where; // update the pixel-array loadPixels(); System.arraycopy(frames[currentFrame].pixels, 0, pixels, 0, width * height); updatePixels(); // set the jump time lastJumpTime = parent.millis(); } }
/* * the thread's run method */ public void run() { while (Thread.currentThread() == runner) { try { Thread.sleep(5); } catch (InterruptedException e) { } if (play) { // if playing, check if we need to go to next frame if (parent.millis() - lastJumpTime >= delays[currentFrame]) { // we need to jump if (currentFrame == frames.length - 1) { // its the last frame if (loop) { jump(0); // loop is on, so rewind } else if (!ignoreRepeatSetting) { // we're not looping, but we need to respect the // GIF's repeat setting repeatCount++; if (repeatSetting == 0) { // we need to repeat forever jump(0); } else if (repeatCount == repeatSetting) { // stop repeating, we've reached the repeat // setting stop(); } } else { // no loop & ignoring the repeat setting, so just // stop. stop(); } } else { // go to the next frame jump(currentFrame + 1); } } } } }