使用Processing + Eclipse在屏幕上显示实时文本的文本对象

时间:2014-11-22 20:46:29

标签: java eclipse processing

我目前有一个多类程序,它使用Eclipse中设置的处理库。我想知道是否存在第三方库中的Text对象,我可以使用它来在屏幕上创建文本对象,而且至关重要的是,移动这些文本对象而不必将它们重绘为屏幕。那里有没有这样的课程?

EG。一个名为Text init的类为Text textObject = new Text("String", x, y) 使用类似于textObject.move(dx, dy)

的方法

1 个答案:

答案 0 :(得分:0)

如果您没有找到要执行此操作的库,那么这是一个最小的实现。如果你愿意,我可以将它包装在一个库中,以便对象自己绘制。如果你正在使用eclipse,你可能需要在PApplet调用之前添加一些parent.

TextObject to;

void setup(){
  size(400,400);
  to = new TextObject("test", 0, height/2);
}

void draw(){
  background(0);
  if(frameCount % 300 == 0) to.set(0, height/2);
  to.move(1,0);
  to.display();
}

class TextObject
{
  float x, y;
  String text;
  PFont f;

  TextObject(String s, float x, float y){
    this.x = x;
    this.y = y;
    this.text = s;
    f = createFont("Georgia", 32);
  }
  TextObject(String s, float x, float y, PFont f){
    this.x = x;
    this.y = y;
    this.text = s;
    this.f = f;
  }
  void set(float x, float y){
    this.x = x;
    this.y = y;
  }
  void move(float dx, float dy){
    x += dx;
    y += dy;    
  }
  void display(){
    textFont(f);
    text(text, x, y);
  }
}