I am trying to update the text rendered on the screen after the health of a player changes. The problem I am having is deciding where to update this. The player and health graphics are separate objects.
Currently,my code is organized like this: The main c++ has vectors:
- vector< Players>
- vector< Renderables>
"Renderables" is anything that can be rendered. It has a member function render() which is called for every object in the vector. A "Text" class inherits from it. It contains the string that is displayed on screen. "Text" has its own render function, and calls its member function getString() inside its render function.
The question is where do I update this string once the player's health has changed?
My current solution is actually to have a "PlayerHealth" subclass of "Text", which holds a pointer to the player. That way "PlayerHealth"can just redefine getString() as player->health converted to a string, and using "Text"'s render function. But I've been told this wasn't a very good method and was wondering what other approaches there were to this problem.
Thank you for your time