1/**
2 * Sprite (Teddy)
3 * by James Patterson.
4 *
5 * Demonstrates loading and displaying a transparent GIF image.
6 */
7
8PImage teddy;
9
10float xpos;
11float ypos;
12float drag = 30;
13
14void setup() {
15  size(200, 200);
16  teddy = loadImage("teddy.gif");
17  xpos = width/2;
18  ypos = height/2;
19}
20
21void draw() {
22  background(102);
23
24  float difx = mouseX - xpos-teddy.width/2;
25  if (abs(difx) > 1) {
26    xpos = xpos + difx/drag;
27    xpos = constrain(xpos, 0, width-teddy.width);
28  }
29
30  float dify = mouseY - ypos-teddy.height/2;
31  if (abs(dify) > 1) {
32    ypos = ypos + dify/drag;
33    ypos = constrain(ypos, 0, height-teddy.height);
34  }
35
36  // Display the sprite at the position xpos, ypos
37  image(teddy, xpos, ypos);
38}
39