[Solved] [Libgdx] Vector2 won't set

So I have this code right here:


//...
//put package and imports here
//...

public class Map implements Disposable {
    //...
    //put other variables here
    //...

    private Vector2[] cellAroundPlayer;
    private float offset;
  
    public Map(String mapTmx, float tileSize, float camTileSize, Player player1) {
        //...
        //other stuff here
        //...
        cellAroundPlayer = new Vector2[4];
        Arrays.fill(cellAroundPlayer, new Vector2());
        offset = 1f;
    }
    
    public void render() {
        //...
        System.out.println("Player Pos: " + player.getMiddleOriginX() + ", " + player.getMiddleOriginY());
        cellAroundPlayer[0].set((int)player.getMiddleOriginX(), (int)(player.getMiddleOriginY() + offset));
        cellAroundPlayer[1].set((int)player.getMiddleOriginX(), (int)(player.getMiddleOriginY() - offset));
        cellAroundPlayer[2].set((int)(player.getMiddleOriginX() + offset), (int)player.getMiddleOriginY());
        cellAroundPlayer[3].set((int)(player.getMiddleOriginX() - offset), (int)player.getMiddleOriginY());
        
        System.out.println("Cells around player: " + cellAroundPlayer[0] + ", " + cellAroundPlayer[1] + ", " + cellAroundPlayer[2] + ", " + cellAroundPlayer[3]);
        
        //...
    }
    
    //put other methods here
}


So you probably think: hmm a Vector2[4] which contains four Vector2()'s and they get set to the positions of the cells around the player.

The first println() says:


Player Pos: 0.5, 3.5

So this means that (int)player.getMiddleOriginX() = 0 and (int)player.getMiddleOriginY() = 3 right?
And since offset = 1, this means that:


cellAroundPlayer[0] //0, 4
cellAroundPlayer[1] //0, 2
cellAroundPlayer[2] //1, 3
cellAroundPlayer[3] //-1, 3

(Note: 0, 1, 2, 3 means North, South, East and West)

But that’s not what the second println() says!


Cells around player: [0.0:3.0], [0.0:3.0], [0.0:3.0], [0.0:3.0]

What?

I could be doing something wrong, and that the answer is really obvious :clue:, but I couldn’t seem to find it. Any help would be appreciated :slight_smile: