Hello.
I am new to Java and I am creating a simple applet while I to learn.
My problem is that one of my methods doesn't seem to be working.
The applet is a simple moving sprite; use arrows to move, ect.
I am trying to create a missile using the spacebar, however, when I press it the missile is created, but not in the place I want it.
I want it to be created wherever my sprite is standing. I have created a method which finds out the sprite's position, yet this method doesn't work.
It creates the missile at the sprite's starting position, always, regardless if I move.
Here are some code snippets.
Sprite.java:
// Gets x
public int getX() {
return x;
}
// Gets y
public int getY() {
return y;
}
// Sets x
public void setX(int x) {
this.x = x;
}
// Sets y
public void setY(int y) {
this.y = y;
}
Missile.java:
// paints image
public void paint(Graphics g, Main main){
if(visible){
g.drawImage(shotimage, sprite.getX(), sprite.getY(), main);
}
Can anyone help?
Thanks.
P.S Let me know if you need more code.