public void update()
    {
            if (playing)
            {
                    long time = System.currentTimeMillis();
                    if ( time - lastTime > frameDuration[currFrame] && finalFrame != 0)
                    {
                        currFrame++;
                        lastTime = time;
                    }

                    if (currFrame == finalFrame && loop)
                    {
                        currFrame = initialFrame;
                    }
                    else
                        if( (!loop) && (currFrame+1 >= finalFrame) )
                        {
                            currFrame = finalFrame - 1;
                            playing = false;
                        }
            }
    }