Class: Sprite_Timer

Inherits:
Sprite
  • Object
show all
Defined in:
Sprite_Timer.rb

Overview

** Sprite_Timer


This sprite is for timer displays. It monitors $game_timer and automatically

changes sprite states.

Instance Method Summary (collapse)

Constructor Details

- (Sprite_Timer) initialize(viewport)


  • Object Initialization




12
13
14
15
16
# File 'Sprite_Timer.rb', line 12

def initialize(viewport)
  super(viewport)
  create_bitmap
  update
end

Instance Method Details

- (Object) create_bitmap


  • Create Bitmap




27
28
29
30
31
# File 'Sprite_Timer.rb', line 27

def create_bitmap
  self.bitmap = Bitmap.new(96, 48)
  self.bitmap.font.size = 32
  self.bitmap.font.color.set(255, 255, 255)
end

- (Object) dispose


  • Free




20
21
22
23
# File 'Sprite_Timer.rb', line 20

def dispose
  self.bitmap.dispose
  super
end

- (Object) redraw


  • Redraw




53
54
55
56
# File 'Sprite_Timer.rb', line 53

def redraw
  self.bitmap.clear
  self.bitmap.draw_text(self.bitmap.rect, timer_text, 1)
end

- (Object) timer_text


  • Create Text




60
61
62
# File 'Sprite_Timer.rb', line 60

def timer_text
  sprintf("%02d:%02d", @total_sec / 60, @total_sec % 60)
end

- (Object) update


  • Frame Update




35
36
37
38
39
40
# File 'Sprite_Timer.rb', line 35

def update
  super
  update_bitmap
  update_position
  update_visibility
end

- (Object) update_bitmap


  • Update Transfer Origin Bitmap




44
45
46
47
48
49
# File 'Sprite_Timer.rb', line 44

def update_bitmap
  if $game_timer.sec != @total_sec
    @total_sec = $game_timer.sec
    redraw
  end
end

- (Object) update_position


  • Update Position




66
67
68
69
70
# File 'Sprite_Timer.rb', line 66

def update_position
  self.x = Graphics.width - self.bitmap.width
  self.y = 0
  self.z = 200
end

- (Object) update_visibility


  • Update Visibility




74
75
76
# File 'Sprite_Timer.rb', line 74

def update_visibility
  self.visible = $game_timer.working?
end