Game Development Reference
In-Depth Information
The
FrameMove()
function does the following:
The
UpdateScene()
and
ProcessCameraMove()
functions are called only if the
elapsed time since the last update is greater than
k_SecondsPerTick
, which is
the time for one update to occur.
1.
After
UpdateScene()
is called,
m_UpdateTimeCount
is changed to reflect that
an update has happened, by subtracting
k_SecondsPerTick
, which is the time
for a single frame update or “tick.”
2.
3.
If more frame updates have to occur in order to meet the goal of one game
update every
k_SecondsPerTick
, which means that
m_UpdateTimeCount
➤
k_SecondsPerTick
,
UpdateScene()
is called repeatedly, until the elapsed time
since the last game update is equal to or less than
k_SecondsPerTick
.
Listing 10-51. Updating the Game
void FrameMove()
{
m_UpdateTimeCount += m_ElapsedTime;
if (m_UpdateTimeCount > k_SecondsPerTick)
{
while(m_UpdateTimeCount > k_SecondsPerTick)
{
// Update Camera Position
if (m_CameraMoved)
{
ProcessCameraMove();
}
// update the scene
UpdateScene();
m_UpdateTimeCount -= k_SecondsPerTick;
}
}
}
The
onDrawFrame()
function modifications (see Listing 10-52) involve the following:
New code for sound control is added. If
m_SFXOn
is true, the sound
effects are turned on for the arena objects, tanks, and pyramid by calling
TurnSFXOnOff()
. Otherwise, the sound effects are turned off for these game
elements.
1.
2.
The time that has elapsed since the last game update is calculated by calling
the
CalculateFrameUpdateElapsedTime()
function.
The game is updated by calling
FrameMove()
.
3.
The game objects are rendered to the screen by calling
RenderScene()
.
4.