java - getX() works in all my classes except this one -


so made code fishingpole class, , made instance of player.

player player = new player(); imageloader loader = new imageloader(); bufferedimage imagefile = loader.loadimage("/pictures/fishingline.png"); bufferedimage image = imagefile;  public double x, y; public static final double fixed_y = 251;  game game;  public fishingpole(game game){     this.game = game; }  public void tick(){     x = player.getx(); } public void render(graphics g){     g.drawimage(image, (int)x, (int)y, game); }  public void movedown(){  } public void reelin(){  } 

the tick method gets in game loop every time. however, fishing line image doesn't move player. tried see if getx() method worked

public void tick(){     x = player.getx();     system.out.println(player.getx()); } 

that time, when moved player, kept on saying default position of player. tested method inside of other classes , worked fine. code getx() method.

public double getx() {     return this.x; } 

it seem create new instance of player() @ top of class. try passing in player object in constructor (as game), , x that.

your code this:

player player = null;  [snip]  public fishingpole(game game, player player){     this.game = game;     this.player = player; } 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -