我想优化随机多边形区域的位置,为了做到这一点,我必须通过代码动态创建它。但是,当我使用以下内容时:
var n = new RectangularNode();
n.setVisible(true);
n.setPos(20, 20, 0);
n.setSize(500, 500);
n.setFillColor(new Color(40, 40, 40));
level.add(n)
我收到错误消息:
level : Markup element is already initialized and cannot be modified. Please use constructor without arguments, perform setup and finally call initialize() function.
但是当我创建一个新的关卡对象来放入
RectangularNode
时,它不会显示在模拟中。有人可以帮忙吗?
解决方案
var n = new RectangularNode();
n.setVisible(true);
n.setPos(20, 20, 0);
n.setSize(500, 500);
n.setFillColor(new Color(40, 40, 40));
Level level = new Level(this, "myLevel", SHAPE_DRAW_2D3D, 0);
level.add(n);
presentation.add(level);