Class: Osb::Sprite

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

Overview

A still image.

Instance Attribute Summary collapse

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: Layer::Background, origin: Origin::Center, file_path:, initial_position: nil) ⇒ Sprite

Returns a new instance of Sprite.

Parameters:

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

    the layer the object appears on.

  • origin (String) (defaults to: 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 (Osb::Vector2, nil) (defaults to: nil)

    where the object should be by default.



14
15
16
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
# File 'lib/osb/sprite.rb', line 14

def initialize(
  layer: Layer::Background,
  origin: Origin::Center,
  file_path:,
  initial_position: nil
)
  Internal.assert_type!(layer, String, "layer")
  Internal.assert_value!(layer, Layer::ALL, "layer")
  Internal.assert_type!(origin, String, "origin")
  Internal.assert_value!(origin, 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,
      Osb::Vector2,
      "initial_position"
    )
  end

  @layer = layer

  first_command = "Sprite,#{layer},#{origin},\"#{file_path}\""
  if initial_position
    first_command += ",#{initial_position.x},#{initial_position.y}"
  end
  # @type [Array<String>]

  @commands = [first_command]
end

Instance Attribute Details

#commandsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



7
8
9
# File 'lib/osb/sprite.rb', line 7

def commands
  @commands
end

#layerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



7
8
9
# File 'lib/osb/sprite.rb', line 7

def layer
  @layer
end