我正在尝试用Processing创建一个多人游戏,但是无法弄清楚如何将屏幕分成两个以显示玩家的不同情况?
像c#一样,我们有Viewport leftViewport,rightViewport;
解决问题。
非常感谢
答案 0 :(得分:4)
在处理所有绘图操作(如rect,eclipse等)时,在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);
}