(在Eclipse中使用processing库)我该如何使用窗口模式?

3
根据第5步,我在我的Main方法中使用了PApplet.main( new String[] { "--present", "MyGame" });。游戏处于全屏模式,我该如何切换到窗口模式?(我不想仅将其运行为Java Applet...)
谢谢
1个回答

3
如果不想使用窗口模式,只需不传递参数即可:
PApplet.main(new String[] {"MyGame"});

如果您想从当前模式切换到窗口模式,据我所知需要手动处理。 PApplet扩展了Java的 Applet 类,并使用 Frame 将内容添加到其中。以下是一个快速的hack:
import processing.core.PApplet;


public class MyGame extends PApplet {

    public void setup(){
        size(400,400);
        background(255);
        smooth();
        stroke(0,32);
    }
    public void draw(){
        fill(255,1);
        rect(0,0,width,height);
        translate(width/2,height/2);
        rotate(frameCount * .1f);
        line(0,0,width/3,0);
    }
    public void keyPressed(){
        if(key == 'f') exitFullscreen();
    }

    private void exitFullscreen() {
        frame.setBounds(0,0,width,height);
        setBounds((screenWidth - width) / 2,(screenHeight - height) / 2,width, height);
        frame.setLocation((screenWidth - width) / 2,(screenHeight - height) / 2);
        setLocation((screenWidth - width) / 2,(screenHeight - height) / 2);
    }
    public static void main(String args[]) {
        PApplet.main(new String[] { "--present", "MyGame" });
    }
}

可以随意调整 exitFullscreen() 方法以获得所需的设置。


你如何反过来做,即从窗口模式切换到全屏模式? - Koffiman
1
@Koffiman 您可以尝试以下代码:java.awt.Rectangle fs = new java.awt.Rectangle(0, 0, displayWidth, displayHeight); frame.setBounds(fs); setBounds(fs); 但是,问题在于您无法让框架没有装饰(无边框/关闭按钮等)。也许您应该将此作为单独的问题发布,以获取更多答案/建议。 - George Profenza
完成了!你可以在这里发布你的答案,以便开始讨论:https://dev59.com/gH_aa4cB1Zd3GeqPxwZW - Koffiman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接