首页 > 解决方案 > 关于 setup() 函数中的 size()

问题描述

为什么我可以在 setup() 中使用 size(1920, 1080) 但如果我使用

setup()
  visualContext = new VisualContext(
    new Area(0, 0, 1920, 1080),
    new Area(158, 150, 1340, 950)
  );
  size(visualContext.getGlobalArea().getWidth(), visualContext.getGlobalArea().getHeight());

会有错误

When not using the PDE, size() can only be used inside settings().
Remove the size() method from setup(), and add the following:
public void settings() {
  size(1920, 1080);
}

我找不到有关此主题的任何文档。

好奇,size只能用常量初始化吗?

标签: processing

解决方案


如果要使用参数调用大小,请使用设置。

VisualContext visualContext = new VisualContext(
    new Area(0, 0, 1920, 1080),
    new Area(158, 150, 1340, 950)
  );

void settings() {
  size(visualContext.getGlobalArea().getWidth(), visualContext.getGlobalArea().getHeight()); //<>//
}

https://processing.org/reference/settings_.html


推荐阅读