The solution you provided causes the method not to work anymore. . . if I undo it partially works (prints but in wrong place).
Missile.java paint method:
// paints image
public void paint(Graphics g, Main main){
if(visible){
g.drawImage(missileimage, sprite.getX(), sprite.getY(), main);
String variable = String.valueOf(sprite.getX()); // get x
g.drawString(variable, 10, 10); // print current x of sprite
}
}
Main.java:
// Paints
public void paint(Graphics g){
sprite.paint(g, this);
missile.paint(g, this);
Missile.java press space:
// Key detector
public void keyReleased(KeyEvent e){
switch(e.getKeyCode()){
case KeyEvent.VK_SPACE:{
//velshotx = 0;
break;
}
}
}
public void keyPressed(KeyEvent e){
switch(e.getKeyCode()){
case KeyEvent.VK_SPACE:{
visible = true;
break;
}
}
}
// update emthod
public void update(Main main){
main.addKeyListener(this);
}