Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 216
Mars Avatar asked Jul 20 '26 17:07

Mars


1 Answers

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.

like image 141
George Profenza Avatar answered Jul 23 '26 07:07

George Profenza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!