2014-11-22 29 views
0

我目前有一個使用Eclipse中設置的處理庫的多類程序。我想知道是否在第三方庫中有一個Text對象,我可以用它在屏幕上創建文本對象,並且至關重要的是,這些文本對象不必將它們重新繪製到屏幕上。那裏有這樣的課程嗎?用於在Processing + Eclipse屏幕上顯示活動文本的文本對象

例如,一個名爲Text init的類爲Text textObject = new Text("String", x, y) ,方法類似於textObject.move(dx, dy)

+0

這些是唯一的要求嗎?你想讓對象自己繪製,還是要手動調用他們的'draw()'? – kevinsa5 2014-11-23 03:52:32

+0

我最好喜歡他們繪製自己的座標一旦傳入,但明確的電話也將工作 – Satre 2014-11-23 03:54:56

回答

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); 
    } 
} 
相關問題