# Is this paint method okay?

I dont know why i need to call super.paintComponent() and super.repaint() to make the player's movements update, if i just put paintComponent the game seems like to always be stopped. However I think that my mistake is the render() method, if a remove it, it doesn't make any difference, so it is useless, I've been looking for the error but I still can not see it. I would appreciate some help

Here is the paint method of the drawing class

public void paint(Graphics g) {
super.paintComponent(g);

setFocusable(true);
requestFocusInWindow();
setBackground(Color.BLACK);
player.drawPlayer(g, getPosX(), getPosY());
enemy.drawEnemy(g);
//I know this should not be here
super.repaint();
}


Pricipal GameLoop and render method

public void run() {
long lastLoop = System.nanoTime();
final int TARGET_FPS = 60;
final long OPTIM_TIME = 1000000000 / TARGET_FPS;
long lastFPSTime = 0;
int fps = 0;
double delta = 0;

while (running) {
long now = System.nanoTime();
lastLoop = now;
delta += (now - lastLoop) / ((double) TIEMPO_OPTIMO);

lastFPSTime += (now - lastLoop);
fps++;

if (lastFPSTime >= 1000000000) {
System.out.println("[FPS : " + fps + " ]");
lastFPSTime = 0;
fps = 0;
}

while (delta >= 1) {
render();
delta--;
}

try {
Thread.sleep((System.nanoTime() - lastLoop + OPTIM_TIME) / 1000000);
} catch (InterruptedException ex) {
Logger.getLogger(mainGameLoop.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

public void render() {
BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
createBufferStrategy(2);
return;
}
Graphics g = bs.getDrawGraphics();
drawing.paint(g);
g.dispose();
bs.show();
}


And as last and least probable, I thought that maybe there is something that is not adding correctly to my window

A normal window class

Drawing drawing = new Drawing();

public Window(String title,int width, int hight, mainGameLoop mainGame){
JFrame frame = new JFrame(title);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, hight);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);

• The use of a BufferStrategy.show and Java's repaint system are kind of mutually exclusive, if you use the former in your game loop you shouldn't have to call repaint or paintComponent. Can you produce a MCVE that demonstrates why you need to call these two methods? – Thomas Jun 23 '17 at 5:09
paintComponent() method is called when you call repaint(). I used paintComponent(). It's very good solution.