Updating text inside a class [Requesting Help]
in
Programming Questions
•
2 months ago
Hello, I'm trying to make a text class, which will take in a integer variable, and display it on the screen.
My problem, is that when I add a new object to the ArrayList, the integer is used in the class, but it's never updated: eg.
text.add(new TextBlock(new PVector(180, 120), projectile.numberOfBullets, constantia20));
So, if I'm trying to get the TextBlock to display the number of bullets that the player has, the TextBlock will take in the current bullets, but it won't update if the "numberOfBullets" variable is changed. I'm guessing that this is because the class takes in the value of the "numberOfBullets" variable, but it doesn't actually take in the variable itself.
What can I do to get around this problem? Any help will be appreciated.
EDIT: Just to clarify, I'd like to have " text(intNum, pos.x, pos.y);" behave as though it was written like " text(projectile.numberOfBullets, pos.x, pos.y);".
My problem, is that when I add a new object to the ArrayList, the integer is used in the class, but it's never updated: eg.
text.add(new TextBlock(new PVector(180, 120), projectile.numberOfBullets, constantia20));
So, if I'm trying to get the TextBlock to display the number of bullets that the player has, the TextBlock will take in the current bullets, but it won't update if the "numberOfBullets" variable is changed. I'm guessing that this is because the class takes in the value of the "numberOfBullets" variable, but it doesn't actually take in the variable itself.
What can I do to get around this problem? Any help will be appreciated.
EDIT: Just to clarify, I'd like to have " text(intNum, pos.x, pos.y);" behave as though it was written like " text(projectile.numberOfBullets, pos.x, pos.y);".
-
class TextBlock extends Menu {int intNum;TextBlock(PVector position, int integer, PFont fSize) {super(position);intNum = integer;fontSize = fSize;}void render() {fill(0);textFont(fontSize);text(intNum, pos.x, pos.y);}}
1