Class: Xibe::Timer
- Inherits:
-
Object
- Object
- Xibe::Timer
- Defined in:
- lib/xibe.rb
Instance Method Summary collapse
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
-
#pause ⇒ Object
Pause counter timer.
-
#paused? ⇒ Boolean
Return true if paused == true.
-
#resume ⇒ Object
Resume counter timer.
-
#start ⇒ Object
Start counter timer.
-
#started? ⇒ Boolean
Return true if started == true.
-
#stop ⇒ Object
Stop counter timer.
-
#ticks ⇒ Object
Return current tick.
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
639 640 641 642 643 644 |
# File 'lib/xibe.rb', line 639 def initialize @start_ticks = 0 @paused_ticks = 0 @paused = false @started = false end |
Instance Method Details
#pause ⇒ Object
Pause counter timer
660 661 662 663 664 665 |
# File 'lib/xibe.rb', line 660 def pause if @started == true && @paused == false @paused = true @paused_ticks = SDL.get_ticks - @start_ticks end end |
#paused? ⇒ Boolean
Return true if paused == true
695 696 697 |
# File 'lib/xibe.rb', line 695 def paused? @paused end |
#resume ⇒ Object
Resume counter timer
668 669 670 671 672 673 674 |
# File 'lib/xibe.rb', line 668 def resume if @paused == true @paused = false @start_ticks = SDL.get_ticks - @paused_ticks @paused_ticks = 0 end end |
#start ⇒ Object
Start counter timer
647 648 649 650 651 |
# File 'lib/xibe.rb', line 647 def start @started = true @paused = false @start_ticks = SDL.get_ticks end |
#started? ⇒ Boolean
Return true if started == true
690 691 692 |
# File 'lib/xibe.rb', line 690 def started? @started end |
#stop ⇒ Object
Stop counter timer
654 655 656 657 |
# File 'lib/xibe.rb', line 654 def stop @started = false @paused = false end |
#ticks ⇒ Object
Return current tick
677 678 679 680 681 682 683 684 685 686 687 |
# File 'lib/xibe.rb', line 677 def ticks t = 0 if @started == true if @paused == true t = @paused_ticks else t = SDL.get_ticks - @start_ticks end end t end |