Class: Fidgit::Cursor

Inherits:
Chingu::GameObject
  • Object
show all
Defined in:
lib/fidgit/cursor.rb

Constant Summary collapse

ARROW =
'arrow.png'
HAND =
'hand.png'

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Cursor

Returns a new instance of Cursor.


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fidgit/cursor.rb', line 8

def initialize(options = {})
  options = {
    image: Gosu::Image[ARROW],
    rotation_center: :top_left,
    zorder: Float::INFINITY
  }.merge!(options)

  super(options)

  nil
end

Instance Method Details

#drawObject


33
34
35
36
# File 'lib/fidgit/cursor.rb', line 33

def draw
  # Prevent system and game mouse from being shown at the same time.
  super if inside_window? and $window.current_game_state.is_a? GuiState and not $window.needs_cursor?
end

#inside_window?Boolean

Is the mouse pointer position inside the game window pane?

Returns:

  • (Boolean)

21
22
23
# File 'lib/fidgit/cursor.rb', line 21

def inside_window?
  x >= 0 and y >= 0 and x < $window.width and y < $window.height
end

#updateObject


25
26
27
28
29
30
31
# File 'lib/fidgit/cursor.rb', line 25

def update
  self.x, self.y = $window.mouse_x, $window.mouse_y

  super

  nil
end