Did I found a bug?

Hello,

Trying do make a delta variable to store the time since the precedent frame I made this sketch. It seems to work fine but after about 1 minute my little sprite is stucked ???

… And now, it runs fullscreen ??? with "size(400,400) !?

(On Linux Mint 18 - I tried with Processing for windows with Wine : sprite stucked too !)

int delta, preMilli=0, milli;

int x=10, direction=1;

void setup() {
  size(400, 400);
  fill(0);
  //frameRate(200);
}

void draw() {
  milli=millis();
  delta=milli-preMilli;
  preMilli=milli;

  background(255);
  text("delta = "+delta, 100, 100);
  text("milli = "+milli, 100, 120);
  text("x = "+x, 100, 140);
  text("framerate = "+frameRate, 100, 160);
  ellipse(x, 250, 20, 20);
  x+=0.2*delta*direction;
  if (x>width-10 || x<10) { 
    direction*=-1;
  }
}
1 Like

No, this is not a bug.

Your circle is getting stuck because you aren’t moving it away from edge when it bounces off of it.

For example, let’s say your circle is travelling left. Its x value is 11, and you subtract 10 so it’s now 1. Your if statement is triggered, so you reverse its direction. On the next frame, you move it right by 5 pixels. Now its x value is 6. Your if statement is triggered again, so you reverse its direction and it’s now travelling left.

You either need to guarantee your minimum movement is large enough, or you need to move the circle when it bounces off an edge.

Shameless self-promotion: here is a tutorial on collision detection in Processing:

2 Likes

Wow ! thanks a lot !

I feel a little silly !!! :smiley:

I’m going to look at your tutorial : :wink: