Why are we using const?

hey! out of curiosity, why are you using a const for clamping camera zoom?

Whenever you have a fixed value, one that won’t change during the course of the game and that is defined in the code, it is best practice to declare that value as a const. This allows the compiler to inject the actual value into the intermediate (compiled) code, which is faster than looking the code up from a variable location (usually the heap).

2 Likes

If a value never changes then you should use a const, in this case I wanted a fixed min and max so a const makes sense.
But if you’d like the camera zoom to have different settings, maybe one scene zooms in further than another scene, then you can easily change that to not be a constant and be regular changeable fields instead.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms