Help, Please!
I have recently been having this problem within my code (java) where subclasses of certain classes share variables with every other instance.
Ex.
public abstract class Entity
{
protected int x, y;
protected int xvel, yvel;
public void setVel(int x, int y)
{
xvel = x;
yvel = y;
}
}
public class Grass extends Entity
{
public void update()
{
x += xvel;
y += yvel;
}
}
in my level class I have a list of Grass objects and so I update them in a for loop, but what I notice is that if I do the following:
entities.get(0).setVel(10, 10);
every single grass object has its velocity set to 10, 10
Please help. I have been struggling with this for 2 days.
I’d just use Eclipse’s global replace and replace all of the Vector2.Zero’s to new Vector2(0,0)’s.