Reputation: 21
I have a class named Button which creates buttons to be displayed on screen. I would like to create an array of information for each button but need to know how many buttons have been created. Is there an easy way to keep track of how many times a class has been instantiated? I have tried this and it doesn't seem to work ... I figured if you put the counter in the constructor it would add one each time, but it doesn't seem to work.
private int children = 0;
public Button(Vector2 position, Vector2 fontPos, Color buttonColor,
String buttonText, Boolean clickable, String spriteName)
{
this.position = position;
this.buttonColor = buttonColor;
this.buttonText = buttonText;
this.clickable = clickable;
this.spriteName += spriteName;
this.fontPos = fontPos;
children++;
}
Upvotes: 2
Views: 2456