【发布时间】:2020-08-04 12:42:41
【问题描述】:
我在一个简单的 Java 项目中使用 processing.core.PApplet 库。
我在setting 函数中加载了多个图像,并尝试在draw 函数中绘制它们,但奇怪的是纹理没有出现?
有我用来加载它们的代码:
public void init() throws FileNotFoundException { // this get executed in the 'setting' function of my sketch
Registry.register(getImage("void"), "void");
}
public processing.core.PImage getImage(String name) throws FileNotFoundException {
String path = "src\\main\\resources\\blocks\\textures\\" + name + ".png";
File file = new File(path);
if(file.exists()) {
Logger.info("Texture " + file.getAbsolutePath() + " found.", "TextureMapping");
return sketch.loadImage(path);
} else {
throw new FileNotFoundException("File " + file.getAbsolutePath() + " not found." );
}
}
以及我用来绘制其中一个的代码:
// I create and draw a new cube in the 'draw' function of my sketch
// But it appears without any texture
public Cube(processing.core.PApplet sketch, BlockPos pos, @NotNull Block block) {
this.sketch = sketch;
this.block = block;
position = pos;
texture = Registry.getTextures().get("minecraft:void");
texture.loadPixels();
}
public void draw() {
sketch.pushMatrix();
sketch.translate(position.getX(), position.getY(), position.getZ());
sketch.box(10);
sketch.texture(texture); // Doin' nothing
sketch.popMatrix();
}
文件在那里,我的Logger 说找到了它们,我没有收到任何错误,但纹理具有 PImage 的所有属性?
第二个奇怪的事情:
在draw 方法之前,我在draw 函数中执行此操作:
sketch.image(Registry.getTextures().get("minecraft:void"), 10, 10);
然后,图像加载完美???
是的,我正在做一个 Minecraft 克隆
【问题讨论】:
标签: java processing textures loadimage