I am making a top down 2D zombie shooter game. Much like the SAS games, there are barricades in the game. The barricades consists of 6 sprites. The sprite that is shown depends on the amount of hitpoints that the barricade has. If the barricade has 90% hit points left, the sprite is changed, if it has 75% left the sprite is changed and so on until the barricade is broken.
The problem is that I get around 21 FPS when there are 4 barricades being damaged by zombies. As soon as the barricades have either broken or the zombies are killed the FPS goes back to about 200. Why so? Is this a bad method for sprite rendering? This is one of my first games, keep that in mind! This is the code:
if (gameObject.GetComponent ().currentHealth >= maxHp) {
gameObject.GetComponent().sprite = undamaged;
}
if (gameObject.GetComponent ().currentHealth < maxHp * 0.99f && gameObject.GetComponent ().currentHealth > maxHp * 0.75f) {
gameObject.GetComponent().sprite = damaged1;
}
if (gameObject.GetComponent ().currentHealth < maxHp * 0.75f && gameObject.GetComponent ().currentHealth > maxHp * 0.6f) {
gameObject.GetComponent().sprite = damaged2;
}
if (gameObject.GetComponent ().currentHealth < maxHp * 0.6f && gameObject.GetComponent ().currentHealth > maxHp * 0.45f) {
gameObject.GetComponent().sprite = damaged3;
}
if (gameObject.GetComponent ().currentHealth < maxHp * 0.45f && gameObject.GetComponent ().currentHealth > maxHp * 0.3f) {
gameObject.GetComponent().sprite = damaged4;
}
if (gameObject.GetComponent ().currentHealth < maxHp * 0.3f && gameObject.GetComponent ().currentHealth > maxHp * 0.15f) {
gameObject.GetComponent().sprite = damaged5;
}
Appreciate some answers!
↧