Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 725 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!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


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: 336
Projects: 2
Exp: 5 years


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.

 

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

The first screenshot will be displayed as a thumbnail.

pw (11 views)
2014-07-24 01:59:36

Riven (9 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (49 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!