(在Eclipse中使用处理库)如何使用窗口模式?

时间:2012-01-17 19:23:29

标签: java processing

http://processing.org/learning/eclipse/根据第5步,我在我的Main方法中使用了PApplet.main( new String[] { "--present", "MyGame" });。游戏处于全屏模式,如何切换到窗口模式?
(我不想将它作为Java Applet运行...)

由于

1 个答案:

答案 0 :(得分:3)

如果您不想使用窗口模式,只需不要传递参数:

PApplet.main(new String[] {"MyGame"});

如果要从当前模式切换到窗口模式,则需要手动处理AFAIK。 PApplet扩展了java的Applet类,并使用Frame来添加内容。 这是一个快速黑客:

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()方法随意修补以获得所需的设置。