Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  // Nenya library - tools for developing networked games
  // Copyright (C) 2002-2012 Three Rings Design, Inc., All Rights Reserved
  // https://github.com/threerings/nenya
  //
  // This library is free software; you can redistribute it and/or modify it
  // under the terms of the GNU Lesser General Public License as published
  // by the Free Software Foundation; either version 2.1 of the License, or
  // (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 package com.threerings.media.animation;
 
 
 
An animation that bobbles an image around within a specific horizontal and vertical pixel range for a given period of time.
 
 public class BobbleAnimation extends Animation
 {
    
Constructs a bobble animation.

Parameters:
image the image to animate.
sx the starting x-position.
sy the starting y-position.
rx the horizontal bobble range.
ry the vertical bobble range.
duration the time to animate in milliseconds.
 
     public BobbleAnimation (Mirage imageint sxint syint rxint ryint duration)
     {
         super(new Rectangle(sx - rxsy - ryimage.getWidth() + rximage.getHeight() + ry));
 
         // save things off
          = image;
          = sx;
          = sy;
          = rx;
          = ry;
 
         // calculate animation ending time
          = duration;
     }
 
     @Override
     public void tick (long tickStamp)
     {
         // grab our ending time on our first tick
         if ( == 0L) {
              = tickStamp + ;
         }
 
          = (tickStamp >= );
         invalidate();
 
         // calculate the latest position
         int dx = RandomUtil.getInt();
         int dy = RandomUtil.getInt();
          =  + dx * (RandomUtil.getBoolean() ? -1 : 1);
          =  + dy * (RandomUtil.getBoolean() ? -1 : 1);
     }
 
     @Override
     public void fastForward (long timeDelta)
     {
          += timeDelta;
     }
 
     @Override
     public void paint (Graphics2D gfx)
     {
         .paint(gfx);
     }
 
     @Override
     protected void toString (StringBuilder buf)
     {
         super.toString(buf);
 
         buf.append(", x=").append();
         buf.append(", y=").append();
         buf.append(", rx=").append();
         buf.append(", ry=").append();
         buf.append(", sx=").append();
        buf.append(", sy=").append();
    }

    
The current position of the image.
    protected int _x_y;

    
The horizontal and vertical bobbling range.
    protected int _rx_ry;

    
The starting position.
    protected int _sx_sy;

    
The image to animate.
    protected Mirage _image;

    
Animation ending timing information.
    protected long _duration_end;
New to GrepCode? Check out our FAQ X