Game Development Reference
In-Depth Information
Save the script, and back in the editor enter Play mode to see the sphere with a random color upon
the start of the game. Notice the r, g, b, a color values also print to the Console. Exit Play mode.
You used Random.Range in Chapter 2, where you learned that the two parameters it accepts are the
minimum and maximum of the range you want the random number selected from. +' Random.Range
to open the Scripting Reference and refresh your memory if necessary.
Frame Rates
Now you've got code setting up the sphere's material color in Start(). Start() only gets called
once, so any further changes to the color needs to take place in Update(). Update() is called every
frame, and the rate at which the game engine renders frames is called frames per second or FPS .
Too slow of a frame rate and the illusion of movement is lost, A higher frame rate means a smoother,
more responsive game experience.
The frame rate of a game in play is constantly changing because it depends upon the number of
computations each frame requires. A single frame can require thousands of calculations, but here
the numbers are kept simple for the sake of illustration. The clunkier (less optimized) your code, the
longer the processing time per frame (Figure 4-13 ).
6 calculations
10 calculations
7 calculations
3 calculations
Frame 1
Frame 2
Frame 3
Frame 4
Figure 4-13. The number of computations can vary for each frame
In addition to the code requirements, computational power of the hardware in the main processor
and graphics chips also puts a limit on frame rates. When you are comparison-shopping for
computers and you see specifications like “2.9 GHz Intel Core i7,” the 2.9 GHz (gigahertz) refers to
the processing speed of the Intel chip's internal “clock.”
In this simplified example, assume that the processor can complete one calculation with each cycle
or “tick” of the clock. Processor A has a slower chip speed than Processor B. Given identical game
conditions, Processor A will have a lower frame rate than Processor B (illustrated by Figure 4-14 ).
Processor A
Processor B
Figure 4-14. Illustration of differing internal clock speeds for two different processors
 
Search WWH ::




Custom Search