How to put the background in a shooting game

Asked 2 years ago, Updated 2 years ago, 35 views

DrawShot or drawPlayer or drawEnemy functions are drawn using fillOval and fillPolygon. If you run it, the game runs on a black screen, and I want to create a background class and use an external image as a background. What should I do?

java

2022-09-22 19:36

1 Answers

Reimplement paintComponent as shown below.

public class Game extends JPanel implements Runnable {
...
...
Image image;

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawImage(image, 0, 0, this);
}


2022-09-22 19:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.