Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (798)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (865)
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  
  Get the mouse x , y? NOT SOLVED  (Read 3257 times)
0 Members and 1 Guest are viewing this topic.
Offline GNecro1
« Posted 2014-07-16 10:54:15 »

Well i get this:
(before i changed static x,y to not static)

(after)


GitHub for the code

i dont know why is it doing this? I want it to go at any angle? why it doesn't ?

Edit: Everything !

Java freak! Cheesy
Offline cylab

JGO Kernel


Medals: 195



« Reply #1 - Posted 2014-07-16 11:20:14 »

Intrestingly your code snippets miss exactly the parts that would allow us to help you,  namely the declarations of your various x and y variables...

Mathias - I Know What [you] Did Last Summer!
Offline GNecro1
« Reply #2 - Posted 2014-07-16 11:28:18 »

I have posted everything now!

Java freak! Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cylab

JGO Kernel


Medals: 195



« Reply #3 - Posted 2014-07-16 11:43:53 »

LOL - still the same - the declaration of x and y is still nowhere too be seen...

Mathias - I Know What [you] Did Last Summer!
Offline GNecro1
« Reply #4 - Posted 2014-07-16 11:45:02 »

The Entity ? :
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  
40  
41  
42  
43  
package Entity;

import java.awt.Graphics2D;
import java.awt.Rectangle;

public class Entity extends Rectangle{
   
   public static double x,y;
   public double drawX;
   public double drawY;
   public int width,height;
   
   public Entity(int x,int y, int width,int height){
      this.x = x;
      this.y = y;
      this.width = width;
      this.height = height;
   }
   
   public void setX(int x){
      this.x = x;
   }
   
   public void setY(int y){
      this.y = y;
   }
   
   public void setWidth(int width){
      this.width = width;
   }
   
   public void setHeight(int height){
      this.height = height;
   }
   
   public void tick(){
     
   }
   
   public void render(Graphics2D g){
     
   }
}

Java freak! Cheesy
Offline Opiop
« Reply #5 - Posted 2014-07-16 11:45:23 »

Could you please explain the relevant code and break it down? I at least don't feel like reading through ~200 lines of someone else's code to solve what is most likely a basic problem, no offense.

Edit:
Read up on static. Those static x and y variables are... Like nails on a chalkboard. I don't think you understand what you're doing there.
Offline GNecro1
« Reply #6 - Posted 2014-07-16 11:50:14 »

Thank you! But why is it doing that?

Java freak! Cheesy
Offline Opiop
« Reply #7 - Posted 2014-07-16 11:53:59 »

Static creates one instance of the variable for the entire program at runtime. Only one instance. So whenever you change a static variable, any objects that utilize that variable will also be affected. Sounds weird so let me give you an example.

You have an Entity class with the static variables x and y. You create two instances of the Entity variable. Both entities now have the same x and y variables because they are static and so if you change the x and y in one entity, the x and y variables in the other will change also to be the exact same. Essentially you are sharing a variable between multiple objects when you use the static keyword.

Hope that actually made sense.
Offline Aboogesnickle

Senior Newbie


Exp: 1 month or less



« Reply #8 - Posted 2014-07-16 22:56:30 »

If you are talking about the it only shooting at certain angles, most of the time something is getting changed to a int were it should be a double.
Offline GNecro1
« Reply #9 - Posted 2014-07-16 23:01:04 »

It's not solved Sad!

Java freak! Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline GNecro1
« Reply #10 - Posted 2014-07-17 21:42:46 »

 Emo Well you helped but the code is still not working
i still get chunks


Source on GitHub

Java freak! Cheesy
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (81 views)
2019-09-04 15:33:17

hadezbladez (4332 views)
2018-11-16 13:46:03

hadezbladez (1546 views)
2018-11-16 13:41:33

hadezbladez (4460 views)
2018-11-16 13:35:35

hadezbladez (863 views)
2018-11-16 13:32:03

EgonOlsen (4152 views)
2018-06-10 19:43:48

EgonOlsen (4855 views)
2018-06-10 19:43:44

EgonOlsen (2803 views)
2018-06-10 19:43:20

DesertCoockie (3707 views)
2018-05-13 18:23:11

nelsongames (3998 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
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!