HUD delay when is following the object

“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

draw function

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


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



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 "";}
}
1 Like

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”.