Class: Rubygame::Events::ClockTicked
- Inherits:
-
Object
- Object
- Rubygame::Events::ClockTicked
- Defined in:
- lib/rubygame/events/clock_events.rb
Overview
ClockTicked is an event returned by Clock#tick, if the Clock has been configured with Clock#enable_tick_events.
ClockTicked stores the time that has passed since the previous tick. You can access that information with #seconds or #milliseconds. This is useful to calculate how far a character should move during the current frame, for example.
Instance Method Summary collapse
-
#initialize(milliseconds) ⇒ ClockTicked
constructor
Create a new ClockTicked event.
-
#milliseconds ⇒ Object
Return the time since the last tick, in milliseconds.
-
#seconds ⇒ Object
Return the time since the last tick, in seconds.
Constructor Details
#initialize(milliseconds) ⇒ ClockTicked
Create a new ClockTicked event.
- milliseconds
-
The time since the last tick, in milliseconds. (Numeric, required)
42 43 44 |
# File 'lib/rubygame/events/clock_events.rb', line 42 def initialize( milliseconds ) @milliseconds = milliseconds end |
Instance Method Details
#milliseconds ⇒ Object
Return the time since the last tick, in milliseconds.
47 48 49 |
# File 'lib/rubygame/events/clock_events.rb', line 47 def milliseconds @milliseconds end |
#seconds ⇒ Object
Return the time since the last tick, in seconds.
52 53 54 |
# File 'lib/rubygame/events/clock_events.rb', line 52 def seconds @seconds or (@seconds = @milliseconds * 0.001) end |