[SOLVED] Appropriate way to show damage numbers

Hello.

In my game I have bullets, when the bullets hits some enemies I want the show the damage on top of the enemy.

I created a logic but I don’t know if it is the best choice, since sometimes I have a lot of bullets and damage in the screen.

  • I’m Using libGDX, target is mobile.
  • Bullet: I create bullets using Pool and Poolable.
  • When the bullet hits the enemy, the enemy’s HP is decreased and I add the current position and the damage received to an Array.
  • In draw() method I just draw the numbers and increase the Y position for some motion and if the Y position is bigger than the start position + 30, I remove from the list.

Everything is working fine, but what is the best way to deal with this values (position and damage) for each damage, since I have a lot of damage created everytime? I’m going to use Pool and Poolable again to re-use objs as I did with Bullets, but I’m here first to know if I’m doing right.

public class DamageAnimation
{
	private int damage;
	private int x;
	private int y;
	private int max;
	
	public DamageAnimation(int damage, int x, int y)
	{
		this.damage = damage;
		this.x = x;
		this.y = y;
		max = y+30;
	}
	
	public int getX()
	{
		return x;
	}
	
	public int getY()
	{
		return y++;
	}
	
	public int getDamage()
	{
		return damage;
	}
	
	public int getMax()
	{
		return max;
	}
}

n = listDamage.size;
for (int i=0; i<n; i++)
{
	DamageAnimation damageDraw = listDamage.get(i);
	fontTest.draw(batch, String.valueOf(damageDraw.getDamage()), damageDraw.getX(),
			damageDraw.getY());
	if (damageDraw.getY() > damageDraw.getMax())
		listDamage.removeValue(damageDraw, true);
}