Game Development Reference
In-Depth Information
Frame Skipping
You will see strange things happening at very low framerates. For example, bullet
explosions are showing up frame by frame, so explosion speed seems way too slow and
unrealistic. To avoid that, we will modify our Explosion class to employ frame skipping
if update rate is too slow:
# 04-prototype-optimized/explosion.rb
class Explosion
FRAME_DELAY = 16.66 # ms
# ...
def update
advance_frame
end
def done?
@done ||= @current_frame >= animation . size
end
# ...
private
# ...
def advance_frame
now = Gosu . milliseconds
delta = now - ( @last_frame ||= now)
if delta > FRAME_DELAY
@last_frame = now
end
@current_frame += (delta / FRAME_DELAY ) . floor
end
end
Now our prototype is playable even at lower frame rates.
Search WWH ::




Custom Search