Class: Xibe::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/xibe.rb

Instance Method Summary collapse

Constructor Details

#initializeTimer

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

#pauseObject

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

Returns:

  • (Boolean)


695
696
697
# File 'lib/xibe.rb', line 695

def paused?
  @paused
end

#resumeObject

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

#startObject

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

Returns:

  • (Boolean)


690
691
692
# File 'lib/xibe.rb', line 690

def started?
  @started
end

#stopObject

Stop counter timer



654
655
656
657
# File 'lib/xibe.rb', line 654

def stop
  @started = false
  @paused = false
end

#ticksObject

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