简体   繁体   English

Java处理项目中未显示背景

[英]Background not showing up in java processing project

I think I'm doing everything right in my code but my background won't show up in my processing project, here is my code. 我认为我在代码中所做的一切正确,但是我的背景不会出现在我的处理项目中,这是我的代码。

package finalproject;
import processing.core.PApplet;
import processing.core.PImage;

public class FinalProject extends PApplet {
    PImage background;
    PImage player;
    public void setup() {
        size(1360, 1080);
        player = loadImage("player.png");       
        background  = loadImage("rust.png");
    }

    public void draw() {
        background(background);
        image(player, 500, 500);
    }
}

Processing expects files to be inside a data directory next to the code. 处理期望文件位于代码旁边的data目录中。

You're presumably running this from an IDE like Eclipse instead of the Processing editor, so where you put that data directory depends on how your code is setup. 大概是从Eclipse之类的IDE而不是Processing编辑器运行它,因此放置该data目录的位置取决于代码的设置方式。 And you haven't posted a MCVE , so it's hard to help you with that. 而且您还没有发布MCVE ,因此很难为您提供帮助。

But basically, you need to debug your sketch to figure out exactly where Processing is looking for the files. 但基本上,您需要调试草图以准确确定Processing正在寻找文件的位置。 Then you need to move the files there. 然后,您需要将文件移到那里。 This is probably something simple like putting them inside a data directory. 这可能很简单,例如将它们放在data目录中。

If you still can't get it working, please post a MCVE along with a screenshot or a description of your directory structure. 如果仍然无法正常运行,请发布MCVE以及屏幕截图或目录结构的描述。

If you are using the processing IDE than the data folder should be located in your sketch folder next to all the .pde files. 如果使用的是处理IDE,则应在草图文件夹中所有.pde文件旁边找到数据文件夹。 Make sure that the image you are using has the same resolution as the sketch window. 确保您使用的图像具有与草图窗口相同的分辨率。 If you are still having issues I would recommend that you try moving your setup and draw methods out of your class and into the main processing sketch. 如果仍然有问题,建议您将设置和绘图方法移出类,移至主要处理草图中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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