# Did I found a bug?

**URL:** https://discourse.processing.org/t/did-i-found-a-bug/7946
**Category:** Coding Questions
**Created:** [January 29, 2019, 8:23pm UTC](https://discourse.processing.org/t/did-i-found-a-bug/7946 "2019-01-29T20:23:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![EricRogerGarcia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ericrogergarcia/32/21029_2.png) [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)
#### Post date: [January 29, 2019, 8:23pm UTC](https://discourse.processing.org/t/did-i-found-a-bug/7946/1 "2019-01-29T20:23:27Z")

</div>

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 !)

```auto
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;
  }
}

```

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [January 29, 2019, 8:29pm UTC](https://discourse.processing.org/t/did-i-found-a-bug/7946/2 "2019-01-29T20:29:16Z")

</div>

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:

> **[Processing Collision Detection](https://happycoding.io/tutorials/processing/collision-detection)**
>
> Learn how to trigger an action when objects overlap in Processing!

---

<div class="post-metadata">

### Author: ![EricRogerGarcia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ericrogergarcia/32/21029_2.png) [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)
#### Post date: [January 29, 2019, 8:32pm UTC](https://discourse.processing.org/t/did-i-found-a-bug/7946/3 "2019-01-29T20:32:20Z")

</div>

Wow ! thanks a lot !

I feel a little silly !!! 😃

I’m going to look at your tutorial : 😉
