Class: UI::Casino::NumberDisplay

Inherits:
SpriteStack show all
Defined in:
scripts/01300 UI/09003 Casino/00001 NumberDisplay.rb

Overview

Object showing images of credit / payout element in casino UI

Constant Summary collapse

FILES =

List of files that shows the number

%w[casino/n0 casino/n1 casino/n2 casino/n3 casino/n4
casino/n5 casino/n6 casino/n7 casino/n8 casino/n9]
DELTA =

Delta of number between each frame

3

Constants inherited from SpriteStack

SpriteStack::NO_INITIAL_IMAGE

Instance Attribute Summary collapse

Attributes inherited from SpriteStack

#animated, #data, #moving, #stack, #viewport, #x, #y

Instance Method Summary collapse

Methods inherited from SpriteStack

#[], #add_background, #add_line, #add_text, #anime, #anime_delta_set, #dispose, #each, #execute_anime, #move, #move_to, #opacity, #opacity=, #push, #push_sprite, #set_origin, #set_position, #simple_mouse_in?, #size, #stop_animation, #translate_mouse_coords, #update_animation, #update_position, #visible, #visible=, #with_cache, #with_font, #with_surface, #z, #z=

Constructor Details

#initialize(viewport, x, y, max_numbers) ⇒ NumberDisplay

Create a new NumberDipslay

Parameters:



23
24
25
26
27
28
29
30
31
# File 'scripts/01300 UI/09003 Casino/00001 NumberDisplay.rb', line 23

def initialize(viewport, x, y, max_numbers)
  super(viewport, x, y)
  width = number_width
  max_numbers.times do |i|
    add_sprite((max_numbers - i - 1) * width, 0, NO_INITIAL_IMAGE)
  end
  @number = 0
  @target = 0
end

Instance Attribute Details

#numberInteger

Number that is currently displayed

Returns:



13
14
15
# File 'scripts/01300 UI/09003 Casino/00001 NumberDisplay.rb', line 13

def number
  @number
end

#targetInteger

Target that the UI element should animatedly aim

Returns:



16
17
18
# File 'scripts/01300 UI/09003 Casino/00001 NumberDisplay.rb', line 16

def target
  @target
end

Instance Method Details

#done?Boolean

Tell if the animation is done

Returns:

  • (Boolean)


54
55
56
# File 'scripts/01300 UI/09003 Casino/00001 NumberDisplay.rb', line 54

def done?
  @number == @target
end

#update

Update the animation



42
43
44
45
46
47
48
49
50
# File 'scripts/01300 UI/09003 Casino/00001 NumberDisplay.rb', line 42

def update
  return if done?
  if @target > @number
    @number = (@number + DELTA).clamp(@number, @target)
  else
    @number = (@number - DELTA).clamp(@target, @number)
  end
  update_numbers
end