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
Post a Comment