I would like to ask you guys especially the professionals what is the easiest ways too add pictures as your background without editing too much code or better yet making a new class that imports the picture and displays it on the screen??? ~Devin
Just load a picture that is the width and height of your screen (if your level scrolls thats a whole different issue… ) then when you draw your objects, simply draw the background image first so that when other images are drawn, they are drawn over the background. Can I ask what you’ve tried so far? Its honestly a very basic thing to do if you’ve already learned how to load images.
I forget I’ve tried once i watched THEBCBROZ Java 2 D Game development video 7 Importing images and their method doesn’t work a lot of people are having issues with it so i’m wondering if there is an easy way to do it by making a new class and editing as little code as possible!
Please Help! ~Devin
public BufferedImage loadImage(String filepath) {
try {
return ImageIO.read(new File(filepath));
}
catch (IOException e) {
}
return null;
}
BufferedImage background = loadImage(path);
The draw it with g.drawImage