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

Returns a new instance of Animation.

Parameters:

  • layer (String) (defaults to: Osb::Layer::Background)

    the layer the object appears on.

  • origin (String) (defaults to: Osb::Origin::Center)

    where on the image should osu! consider that image’s origin (coordinate) to be.

  • file_path (String)

    filename of the image.

  • initial_position (Vector2, nil) (defaults to: nil)

    where the object should be by default.

  • frame_count (Integer)

    how many frames the animation has.

  • frame_delay (Integer)

    how many milliseconds should be in between each frame.

  • repeat (Boolean) (defaults to: false)

    if the animation should loop or not.



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