PShape 2.08 使用 createShape 抛出 NullPointerException [英] PShape 2.08 throws NullPointerException with createShape
问题描述
我在 Mac 上使用 Processing 2.08.我正在尝试使用文档中给出的 createShape 函数创建一个 PShape.
I am using Processing 2.08 on mac. I am trying to create a PShape using the createShape function as given in the documentation.
PShape s;
void setup(){
size(500,500);
s = createShape();
s.beginShape(QUADS);
s.fill(0);
s.vertex(100,100);
s.vertex(100,300);
s.vertex(300,300);
s.vertex(300,100);
s.endShape();
}
void draw(){
shape(s);
}
但是这个程序抛出了 NullPointerException.在 Processing.org 论坛上查找时,我发现一个帖子说新的处理库有这个问题.
But this program throws NullPointerException. Upon looking up on the Processing.org forum I found a thread saying that the new processing library has problem with this one.
参考:https://forum.processing.org/topic/changes-to-pshape-in-2-08
我如何使这项工作?有什么解决方法吗?谢谢
How do I make this work? Is there any workaround? Thanks
推荐答案
来自文档:
用于存储形状的数据类型.处理当前可以加载和显示SVG(可缩放矢量图形)和 OBJ 形状.在使用形状之前,它必须使用 loadShape() 函数加载.shape() 函数用于将形状绘制到显示窗口.PShape 对象包含一组方法,链接如下,可以对形状数据.OBJ 文件只能使用 P3D 渲染器打开.
Datatype for storing shapes. Processing can currently load and display SVG (Scalable Vector Graphics) and OBJ shapes. Before a shape is used, it must be loaded with the loadShape() function. The shape() function is used to draw the shape to the display window. The PShape object contains a group of methods, linked below, that can operate on the shape data. OBJ files can only be opened using the P3D renderer.
您可以在此处找到参考:http://processing.org/reference/PShape.html一个>
You can find the reference here: http://processing.org/reference/PShape.html
简而言之,目前,如果不先在别处创建形状,就不能使用 PShape.
In short, for now, you can't use PShape without first creating a shape elsewhere.
您可以单独创建一个图像,将其保存在文件中,然后使用 PShape 加载它.这是一个黑客,但至少在他们提出更合适的解决方案之前,它可以使用 PShape.
You could just create an image independently, save it on file and then load it with PShape. Its a hack but it makes it possible to use PShape at least until they can come up with a more proper fix.
这篇关于PShape 2.08 使用 createShape 抛出 NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!