I have a class where some variables are initialized with static final
. This variables have a defined initial value that is used in it's same class, and in another class.
Now, I want the value of this variables to be dependant of a scale_factor:
From this:
class Ball {
public static final float SPEED = 4.0f;
//...
To this:
class Ball {
public static final float SPEED = 4.0f * scale_factor;
//...
Sopposing that scale_factor
is another float with value from 1.0 to 3.0.
The problem is that if I do this, I get this error:
The field SPEED cannot be declared static in a non-static inner type,
unless initialized with a constant expression
It suggest to remove the static modifier of SPEED. If I do it, then, I cannot use this variable in other classes cause it tells me to make it static to be able to use it.
UPDATE--
public class SinglePlayerView extends View {
//...
public static float scale_factor;
//...
public SinglePlayerView(Context context) {
super(context);
scale_factor = setScreenScale();
}
public float setScreenScale() {
float scale = getResources().getDisplayMetrics().density;
return scale;
}
class Ball {
public float x, y, xp, yp, vx, vy;
public float speed = SPEED;
public static final double BOUND = Math.PI / 9;
public static final float SPEED = 4.0f;
public static final int RADIUS = 4;
public static final double SALT = 4 * Math.PI / 9;
public Ball() {
}
public Ball(Ball other) {
x = other.x;
y = other.y;
xp = other.xp;
yp = other.yp;
vx = other.vx;
vy = other.vy;
speed = other.speed;
mAngle = other.mAngle;
}
//...
The parameters I would need to multiply the scale_factor are SPEED
and RADIUS