Good day. I implemented a script to gradually decrease the light source of my character in game. This serves as the game's timer. I use a Spot Light as the light source and adjust its spot angle proportional to the elapsed time. However, I observed that the frame rate drops gradually as the light depletes. I'm wondering what's causing this behavior or is it the light that really affect the game's frame rate. Below is my code for the Spot Light adjustment.
private void UpdateLight() {
this.timer.Update();
float timePercentage = (this.duration - this.timer.TimeElapsed()) / this.duration;
float newAngle = this.light.spotAngle;
if(timePercentage > 0.75f) {
newAngle = this.lightPower;
}
else if(timePercentage > 0.50f) {
newAngle = (0.9f * this.angleRange) + Constants.MIN_LIGHT_ANGLE;
}
else if(timePercentage > 0.25f) {
newAngle = (0.75f * this.angleRange) + Constants.MIN_LIGHT_ANGLE;
}
else if(timePercentage > 0.1f) {
newAngle = (0.25f * this.angleRange) + Constants.MIN_LIGHT_ANGLE;
}
else if(timePercentage > 0.0f) {
newAngle = Constants.MIN_LIGHT_ANGLE;
}
if(this.timer.HasElapsed()) {
RenderSettings.ambientLight = Color.black;
Destroy(this.gameObject);
}
if(newAngle != this.light.spotAngle) {
this.light.spotAngle = newAngle;
GameManager.Instance.StrataHud.UpdateLightBar(timePercentage);
}
}
There's a flag for my light source which tells if the light is permanent or depleting. The frame rate drop happens when the light is depleting which is the condition for UpdateLight function to trigger.
The UpdateLight function is invoked in the Update routine of the object. If it will help, my scene is made up of tk2d sprites with lit shaders. It's tile based and so far I'm playing on a 18 x 35 tile scene with each tile measuring 256px by 256px. I'm using the free version of Unity.
If it helps, here's my list of the running processes. Not sure if I can enumerate them all but this is what I've reviewed so far:
- character movements (current action of character and monsters)
- HUD processes (progress bars, label changes, notification handling made up of text)
- Hint detection (triggered periodically by specific type of objects in order to trigger the hint arrow. This is done by measuring the vector distance from the character to the object. Each hintable object has this process)
↧