简体   繁体   中英

Resizing multiple applets in Processing

I'm using the code from this answer and I have an issue with changing the size of the first applet. Changing values of size(100, 100) does nothing.How can I fix this problem?

public void setup() {
  size(100, 100);

  String[] args = {"TwoFrameTest"};
  SecondApplet sa = new SecondApplet();
  PApplet.runSketch(args, sa);
}

void draw() {
  background(0);
  ellipse(50, 50, 10, 10);
}     

public class SecondApplet extends PApplet {

  public void settings() {
    size(500, 500);
  }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
}

An easy fix is to just move the first size() into the settings() function:

void settings() {  
  size(500, 100);
}

void setup() {
  String[] args = {"TwoFrameTest"};
  SecondApplet sa = new SecondApplet();
  PApplet.runSketch(args, sa);
}

void draw() {
  background(0);
  ellipse(50, 50, 10, 10);
}     

class SecondApplet extends PApplet {

  public void settings() {
    size(500, 500);
  }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
}

I'm not exactly sure why this is happening. I would guess that it has something to do with the fact that you have to call size() from settings() when using eclipse. More info here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM