Animation Overview - News - Installation - Reference - Examples - FAQ  
 

Changing an image in different screen regions
An animation's image can be changed depending on its location on-screen, as shown here.

 

 

Animation test;
BImage happy;
BImage angry;
BFont font;

void setup()
{
  size(400,200);
  happy = loadImage("happy.gif");
  angry = loadImage("angry.gif");
  font = loadFont("RotisSanSer.vlw.gz");
  textFont(font, 26);
  
  test = new Animation(this, happy, 50,75, 300,50);
  test.setDuration(10000);
  test.setStep("ELLIPSE");
  test.setTest("myTest");
}

void loop()
{
  background(200);
  
  // draw happy
  fill(25,25,230);
  rect(0,0,200,200);
  fill(0);
  text("Happy",75,25);
  
  // draw angry
  fill(230,25,25);
  rect(200,0,400,200);
  fill(0);
  text("Angry",275,25);
      
  test.draw();
}

boolean myTest()
{
  if (test.currentX() > 200)
    test.setImage(angry);
  else
    test.setImage(happy);
  return false;
}