mystery variable type change?

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!

distance() returns a double, but nodeLength is a Point2D :wink:

ahhhh, thankyou :slight_smile:

can I cast distance to give a point?

Distance is a scalar, aka 1 value. How would you put distance into a point, which has an X and Y?

see I’m still thinking like it basically returns a point :stuck_out_tongue: good point!

also, I fixed it, changed nodeLength into an int and cast the calculation into an int so I don’t have horrible decimals to deal with :slight_smile:

Horrible decimals?

yer, it’s not on the code I posted but node length is divided by 20-speed to work out the length of the node and I only want integers so it works more simply with my co-ordinates :slight_smile: