Question about Static and non Static fields

edited October 2015 in Using Processing

I have a game where the ship follows your mouse, but slowly. I use the variables x and y, but they are both equal to a formula that uses other variables to create the slow following movement.

I wanted bullets to regenerate at the ship's location, using Ship.x and Ship.y-- but I keep getting the error, "Cannot make a static reference to the non-static field Ship.x"

What does this mean? Is there a workaround? I have code but I hesitate to post it because I'm new, and my code is very long and messy. I'll learn to clean this up later, but I'd rather not try and re-format all my code at this time.

Tagged:

Answers

  • edited October 2015 Answer ✓

    You try to get variables, using class name Ship. You need to make reference to an instance of ship, that you've created using new keyword: ship = new Ship(); ship.x = ...;

    Static fields are these, that are part of a class itself with no bound to particular instance. To define a static field you need to use a keyword static. But in your case these should not be static.

Sign In or Register to comment.