Home > Net >  Variable math not working in constant declaration
Variable math not working in constant declaration

Time:02-10

I am trying to create the following contant as a class variable public static final Point CENTER = new Point(500, 1794 - VT_SCREEN_CHUNK); to define the center of a screen.

VT_SCREEN_CHUNK is another constant int = 119, so the final value I would like for the Point CENTER is (500, 1675)

However when I print the value of CENTER from a method I get (500, 1794). The variable I substracted is ignored.

Weirdly, if I trySystem.out.println(1794 - VT_SCREEN_CHUNK);, I get I/System.out: 1675. The correct value.

Does anyone have a clue of why I'm unable to do math in the declaration of CENTER? I use math in the creation of some of my other constant ints without an issue so I think it might be a problem with the Point, but I don't really know how to address it!

Any help is appreciated! Thank you!!

EDIT: Sorry about not including code originally, hopefully this remedies that!!

An important note about this, VT_SCREEN_CHUNK is actually a constant from another class that I import. I know it's creation works because when I print VT_SCREEN_CHUNK I correctly get 119.

Please let me know if there is anything else I can provide!

import static dev.Blocks.OtherUtils.VT_SCREEN_CHUNK;
import android.graphics.Point;

public class GameBoard {
    
    public static final Point CENTER_SPAWN = new Point(500, 1794 - VT_SCREEN_CHUNK);
    
    public GameBoard() {
        
    }
    
    public void printDebug() {

        System.out.println("CENTER is: "CENTER);
        System.out.println("VT Screen chunk is: "  VT_SCREEN_CHUNK);
        System.out.println(1794 - VT_SCREEN_CHUNK);
    }
    
}

The above print statements show the following that I had already mentioned...

out: Center is: 1794
out: VT Screen chunk is: 119
out: 1675

Finally, here is a skeleton of the class where I get VT_SCREEN_CHUNK.

public class OtherUtils {

    // Where PolyGoneUtils.getScreenHeight() gets the height of a screen as an integer.
    final public static int VT_SCREEN_CHUNK = PolyGoneUtils.getScreenHeight() / 15;
    
    public OtherUtils() {}
    
}

CodePudding user response:

  •  Tags:  
  • Related