Hi Guys,
I use a typical “Vector2f” type class for storing my entities positions, velocities etc and had a question about best practices when it comes to reassigning the objects. In a game loop which runs at 60 fps, I am updating my cameras position using my players position…
camera.setPosition(player.getPosition());
The player.getPosition is returning a Vector2f object and my camera class is then reassigning its position as a new object…
public void setPosition(Vector2f pos) {
this.position = new Vector2f(pos);
}
If this is happening 60 times per second, am I generating 60 obsolete objects which will require garbage collection at some stage? If this is the case, should I be getting into the habit of assigning the new position as shown below?
public void setPosition(Vector2f pos) {
this.position.x = pos.x;
this.position.y = pos.y;
}
I doubt this will effect performance in any noticeable way but I would like to make sure that I am developing good habits as I go with programming.
Cheers guys.