(using processing library in Eclipse) how do I use window mode?

﹥>﹥吖頭↗ 提交于 2019-12-09 19:37:02

问题


http://processing.org/learning/eclipse/ according step 5, I used PApplet.main( new String[] { "--present", "MyGame" }); in my Main method. The game is in full screen mode, how do I switch to window mode?
(I don't want to just run it as Java Applet...)

Thanks


回答1:


If you don't want to use window mode, simply don't pass the argument:

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

If you want to switch from present mode to window mode, you'll need to handle things manually AFAIK. PApplet extends java's Applet class and uses a Frame to add contents into. Here's a quick 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" });
    }
}

Feel free tinker with the exitFullscreen() method to get the desired setup.



来源:https://stackoverflow.com/questions/8900447/using-processing-library-in-eclipse-how-do-i-use-window-mode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!