Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  mystery variable type change?  (Read 542 times)
0 Members and 1 Guest are viewing this topic.
Offline westloar

Junior Member





« Posted 2012-04-28 10:24:03 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
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:

1  
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!
Offline 65K
« Reply #1 - Posted 2012-04-28 11:19:46 »

distance() returns a double, but nodeLength is a Point2D  Wink

Offline westloar

Junior Member





« Reply #2 - Posted 2012-04-28 11:26:29 »

ahhhh, thankyou Smiley

can I cast distance to give a point?
Games published by our own members! Check 'em out!
Try the Free Demo of Titan Attacks
Offline ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #3 - Posted 2012-04-28 11:37:22 »

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

Offline westloar

Junior Member





« Reply #4 - Posted 2012-04-28 11:39:23 »

see I'm still thinking like it basically returns a point Tongue good point!
Offline westloar

Junior Member





« Reply #5 - Posted 2012-04-28 11:44:40 »

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 Smiley
Offline ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #6 - Posted 2012-04-28 12:12:47 »

Horrible decimals?

Offline westloar

Junior Member





« Reply #7 - Posted 2012-04-28 12:20:25 »

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 Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (84 views)
2013-05-17 21:29:12

alaslipknot (92 views)
2013-05-16 21:24:48

gouessej (123 views)
2013-05-16 00:53:38

gouessej (117 views)
2013-05-16 00:17:58

theagentd (127 views)
2013-05-15 15:01:13

theagentd (114 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.14 seconds with 20 queries.