# HUD delay when is following the object

**URL:** https://discourse.processing.org/t/hud-delay-when-is-following-the-object/17811
**Category:** Coding Questions
**Created:** [February 14, 2020, 2:43am UTC](https://discourse.processing.org/t/hud-delay-when-is-following-the-object/17811 "2020-02-14T02:43:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kisdfnfn](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kisdfnfn](https://discourse.processing.org/u/kisdfnfn)
#### Post date: [February 14, 2020, 2:43am UTC](https://discourse.processing.org/t/hud-delay-when-is-following-the-object/17811/1 "2020-02-14T02:43:41Z")

</div>

“I’m brazilian then, i’m sorry, my english is very poop”

I have a problem, because i’m trying to create a MMORPG with Processing, but my HUD have delay.

Look: [https://imgur.com/ZkFE451](https://imgur.com/ZkFE451)

draw function

```auto
void draw() {
  background(255);
  delta = millis() - lastTime;
  lastTime = millis();

  translate(-player.GetX(true)+(width/2-Map.tile_size/2), -player.GetY(true)+(height/2-Map.tile_size/2));

  player.Update();
  monster.Update();
}

```

Entity class

```auto

class Entity extends HUD {
  private PVector position = new PVector(),
                  last_position = new PVector(),
                  target_position = new PVector(),
                  direction = new PVector();
  private boolean can_walk = false;
  private Entity target = null;
  boolean actor = false;
  int melee = 1,
                  distance = 1,
                  magic = 1,
                  speed = 50;
  float health = 100;
  String nick = "";
  
  Entity(){
    
  }
  void Update(){
    
    this.position.x += this.speed * this.direction.x * delta/1000;
    this.position.y += this.speed * this.direction.y * delta/1000;
    
    if(this.position.dist(this.last_position) >= Map.tile_size - this.speed * delta/1000){
      this.position.set(this.target_position);
    }
    
    if(this.target != null){
      fill(0, 0, 0, 0);
      stroke(255, 0, 0);
      rect(this.target.GetX(true), this.target.GetY(true), Map.tile_size, Map.tile_size);
    }
    
    push();
    stroke(0);
    if(this.actor){
      fill(255);
    }else{
      fill(255, 0, 0);
    }
    translate(this.position.x,this.position.y);
    circle(Map.tile_size/2, Map.tile_size/2, Map.tile_size);
    this.Render();
    pop();
    
    if(this.position.x == this.target_position.x && this.position.y == this.target_position.y){
      this.direction.set(this.GetDirection());
      this.last_position.set(this.position);
      this.target_position.x += this.direction.x * Map.tile_size;
      this.target_position.y += this.direction.y * Map.tile_size;
    }
    
  }
  String GetNick(){
    return this.nick;
  }
  PVector GetDirection(){
    return new PVector();
  }
  PVector SetPosition(PVector position){
    this.last_position.set(position);
    this.target_position.set(position);
    return this.position.set(position.x*32, position.y*32);
  }
  PVector SetPosition(PVector position, boolean absolute){
    if(!absolute){
      position.set(position.x*32, position.y*32);
    }
    this.last_position.set(position);
    this.target_position.set(position);
    return this.position.set(position);
  }
  PVector SetPosition(int x, int y){
    this.last_position.set(x*32, y*32);
    this.target_position.set(x*32, y*32);
    return this.position.set(x*32, y*32);
  }
  PVector SetPosition(int x, int y, boolean absolute){
    if(!absolute){
      x *= 32;
      y *= 32;
    }
    this.last_position.set(x, y);
    this.target_position.set(x, y);
    return this.position.set(x, y);
  }
  PVector GetPosition(boolean absolute){
    float x = this.position.x;
    float y = this.position.y;
    if(!absolute){
      x = floor(x/32);
      y = floor(x/32);
    }
    return new PVector(x, y);
  }
  PVector GetPosition(){
    float x = this.position.x;
    float y = this.position.y;
    x /= 32;
    y /= 32;
    return new PVector(x, y);
  }
  float GetX(){
    return floor(this.position.x/32);
  }
  float GetX(boolean absolute){
    float x = this.position.x;
    if(!absolute) x = floor(x/32);
    return x;
  }
  float GetY(){
    return floor(this.position.y/32);
  }
  float GetY(boolean absolute){
    float y = this.position.y;
    if(!absolute){
      y = floor(y/32);
    }
    return y;
  }
  void SetTarget(Entity target){
    if(!target.actor){
      if(this.target == target){
        this.target = null;
      }else{
        this.target = target;
      }
    }
  }
  void Move(PVector direction){
    if(this.can_walk){
      this.direction.add(direction);
      this.can_walk = false;
    }
  }
  void Move(int x, int y){
    if(this.can_walk){
      this.direction.add(x, y);
      this.can_walk = false;
    }
  }
  
}

```

And the HUD

```auto

class HUD {
  void Render(){
    push();
    fill(0);
    text(this.GetNick(), 0, -10);
    pop();
  }
  
  float GetX(){return 0;}
  float GetX(boolean absolute){return 0;}
  float GetY(){return 0;}
  float GetY(boolean absolute){return 0;}
  String GetNick(){return "";}
}

```

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [February 17, 2020, 12:57am UTC](https://discourse.processing.org/t/hud-delay-when-is-following-the-object/17811/2 "2020-02-17T00:57:35Z")

</div>

> [@kisdfnfn](#):
>
> but my HUD have delay

What does this mean? The HUD is too slow? the HUD is out of sync?

I’m a bit confused about what HUD is, and why Entity extends HUD. That surprised me, like saying “Player extends Map”.
