2011-08-07 71 views
4

我正在嘗試使用Processing創建多人遊戲,但無法弄清楚如何將屏幕拆分爲兩個以顯示玩家的不同情況?處理:如何拆分屏幕?

喜歡在c#中,我們有 Viewport leftViewport,rightViewport; 來解決問題。

非常感謝

回答

4

在處理類似矩形,月食等所有的繪圖操作在PGraphics元素上進行。您可以使用您選擇的渲染器創建兩個新的PGraphic對象,在它們上繪製並將它們添加到您的主視圖中:

int w = 500; 
int h = 300; 
void setup() { 
    size(w, h); 
    leftViewport = createGraphics(w/2, h, P3D); 
    rightViewport = createGraphics(w/2, h, P3D); 
} 

void draw(){ 
    //draw something fancy on every viewports 
    leftViewport.beginDraw(); 
    leftViewport.background(102); 
    leftViewport.stroke(255); 
    leftViewport.line(40, 40, mouseX, mouseY); 
    leftViewport.endDraw(); 

    rightViewport.beginDraw(); 
    rightViewport.background(102); 
    rightViewport.stroke(255); 
    rightViewport.line(40, 40, mouseX, mouseY); 
    rightViewport.endDraw(); 

    //add the two viewports to your main panel 
    image(leftViewport, 0, 0); 
    image(rightViewport, w/2, 0); 


}