Class: Osb::Animation

Inherits:
Object
  • Object
show all
Includes:
Commandable
Defined in:
lib/osb/animation.rb

Overview

A moving image.

Instance Method Summary collapse

Methods included from Commandable

#additive_color_blending, #color, #fade, #flip, #move, #move_x, #move_y, #rotate, #scale, #trigger

Constructor Details

#initialize(layer: Osb::Layer::Background, origin: Osb::Origin::Center, file_path:, initial_position: nil, frame_count:, frame_delay:, repeat: false) ⇒ Animation



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/osb/animation.rb', line 17

def initialize(
  layer: Osb::Layer::Background,
  origin: Osb::Origin::Center,
  file_path:,
  initial_position: nil,
  frame_count:,
  frame_delay:,
  repeat: false
)
  Internal.assert_type!(layer, String, "layer")
  Internal.assert_value!(layer, Osb::Layer::ALL, "layer")

  Internal.assert_type!(origin, String, "origin")
  Internal.assert_value!(origin, Osb::Origin::ALL, "origin")

  Internal.assert_type!(file_path, String, "file_path")
  Internal.assert_file_name_ext!(file_path, %w[png jpg jpeg])
  if initial_position
    Internal.assert_type!(initial_position, Vector2, "initial_position")
  end

  Internal.assert_type!(frame_count, Integer, "frame_count")
  Internal.assert_type!(frame_delay, Integer, "frame_delay")
  Internal.assert_type!(repeat, Internal::Boolean, "repeat")

  @layer = layer

  first_command = "Animation,#{layer},#{origin},\"#{file_path}\""
  if initial_position
    first_command += ",#{initial_position.x},#{initial_position.y}"
  else
    first_command += ",,"
  end
  first_command += ",#{frame_count}"
  first_command += ",#{frame_delay}"
  looptype = repeat ? "LoopForever" : "LoopOnce"
  first_command += ",#{type}" if repeat
  # @type [Array<String>]

  @commands = [first_command]
end