I'm always solving this problem in a dumb way and I know theres a better way.
Suppose I have a Player class, and also a HitPoint class.
The Player object contains an instance of a HitPoint object.
When I draw the player, I also want to draw the hitpoint bar near his head.
So what I end up doing is in the Player's render method, I pass the player's relative position to the HitPoint's render method. So that I can draw the hitpoint bar at the same location of the player, but 50 pixels higher and 10 to the left.
What I'd like to avoid is somehow having to pass positions around like that. It seems like my render code is FULL of ugly little offset maths like xPos + xPos2 + 35.
Example of the problem:
class Player {
int xPos;
int yPos;
HitPoint hpBar;
public void Render() {
DrawThePlayer();
hpBar.Render(xPos, yPos);
}
}
class HitPoint{
public void Render(int x, int y) {
DrawRect(x-10, y-50....
}
}
So for example I'd prefer to have the HitPoint Render method look more like this
class HitPoint{
public void Render() {
DrawRect(0, 0)
}
}
So I'm drwaring the hitpoint bar from (0,0) and not worrying about the Player's position. Something else will "move" the hitpoint bar to the right place.