I’m using Point2D to specify co-ordinates in the game window.
This is working fine, I tried using Point2D.distance using my Point2D variables and it says that I’m entering a double.
I almost know that I am not, just before Point2D.distance is called I use line2D.setLine, using the point arguments, which works fine.
Here’s my code, I even cast the mouseInfo instance into a point2D, but to no avail, please have a look at my code and tell me where I’m going wrong:
public class Boomerang extends Sprite
{
private static double DURATION = 0.5; // secs
// total time to cycle through all the images
private int period; // in ms; the game's animation period
private BricksManager brickMan;
private Point2D[] boomPath;
private int speed; //used to calculate how many nodes to create along the
//boomerangs path.
protected int locx, locy;
private Boolean isVisible;
private JumperSprite rat;
private Line2D path;
private Point2D startPoint;
private Point2D nodeLength;
public Boomerang (int x, int y, BricksManager bm, ImagesLoader imsLd, int p, String name)
{
......
}
public void fire(){
int midx = rat.getWidth()/2; //get the mid point of rat' sprite
int midy = rat.getHeight()/2;
startPoint.setLocation((rat.getXPosn() + midx), (rat.getYPosn() - midy));
//set the start of boomPath to the mid
//positions.
PointerInfo MousePosn = MouseInfo.getPointerInfo();
boomPath[1] = (Point2D) MousePosn.getLocation();
path.setLine(startPoint, boomPath[1]);
nodeLength = startPoint.distance(boomPath[1]);
I’ve tried using different arguments on startPoint and even taking it out and using this:
nodeLength = Point2D.distance(startPoint.getX(), startPoint.getY(), boomPath[1].getX(), boomPath[1].getY());
It again tells me I’m using doubles, I think that boomPath[1] is the culprit, but the api says getLocation() returns a point?
Please help!