简体   繁体   中英

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.

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. And you haven't posted a MCVE , so it's hard to help you with that.

But basically, you need to debug your sketch to figure out exactly where Processing is looking for the files. Then you need to move the files there. This is probably something simple like putting them inside a data directory.

If you still can't get it working, please post a MCVE along with a screenshot or a description of your directory structure.

If you are using the processing IDE than the data folder should be located in your sketch folder next to all the .pde files. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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