Class: Color

Inherits:
Object
  • Object
show all
Defined in:
lib/R3EXS/RGSS3.rb

Overview

RPG Maker VX Ace Color 类

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Color

初始化时接受以下几种参数情况:

  • 无参数时,默认 (0, 0, 0, 0)
  • 3 个参数时,默认为 (red, green, blue, 255)
  • 4 个参数时,指定 (red, green, blue, alpha)

Parameters:

  • args (Array<Integer>)

    red, green, blue, alpha

    • red: 红色通道的值 (0-255)
    • green: 绿色通道的值 (0-255)
    • blue: 蓝色通道的值 (0-255)
    • alpha: 可选,透明度通道的值 (0-255),默认为 255


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/R3EXS/RGSS3.rb', line 17

def initialize(*args)
    case args.length
    when 0 # 无参数
        set(0, 0, 0, 0)
    when 3 # 3 个参数, alpha 默认为 255
        set(*args)
    when 4 # 4 个参数, 分别为 red, green, blue, alpha
        set(*args)
    else
        raise ArgumentError, "Invalid arguments for initialize method"
    end
end

Instance Attribute Details

#alphaInteger

alpha 通道的值

Returns:

  • (Integer)


134
135
136
# File 'lib/R3EXS/RGSS3.rb', line 134

def alpha
  @alpha
end

#blueInteger

blue 通道的值

Returns:

  • (Integer)


129
130
131
# File 'lib/R3EXS/RGSS3.rb', line 129

def blue
  @blue
end

#greenInteger

green 通道的值

Returns:

  • (Integer)


124
125
126
# File 'lib/R3EXS/RGSS3.rb', line 124

def green
  @green
end

#redInteger

red 通道的值

Returns:

  • (Integer)


119
120
121
# File 'lib/R3EXS/RGSS3.rb', line 119

def red
  @red
end

Class Method Details

._load(obj) ⇒ Color

反序列化 Color 对象

Parameters:

  • obj (String)

    序列化后的字符串

Returns:



80
81
82
# File 'lib/R3EXS/RGSS3.rb', line 80

def Color._load(obj)
    new(*obj.unpack('D4'))
end

Instance Method Details

#_dump(level) ⇒ String

序列化 Color 对象

Parameters:

  • level (Integer)

    序列化的级别

Returns:

  • (String)


72
73
74
# File 'lib/R3EXS/RGSS3.rb', line 72

def _dump(level)
    [@red, @green, @blue, @alpha].pack('D4')
end

#set(*args) ⇒ void

This method returns an undefined value.

设置 Color 对象的值

  • 无参数时,默认 (0, 0, 0, 0)
  • 3 个参数时,默认为 (red, green, blue, 255)
  • 4 个参数时,指定 (red, green, blue, alpha)

Parameters:

  • args (Array<Integer>)

    red, green, blue, alpha

    • red: 红色通道的值 (0-255)
    • green: 绿色通道的值 (0-255)
    • blue: 蓝色通道的值 (0-255)
    • alpha: 可选,透明度通道的值 (0-255),默认为 255


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/R3EXS/RGSS3.rb', line 41

def set(*args)
    case args.length
    when 1 # 一个参数, 为 Color 对象
        if args[0].is_a?(Color)
            other_color = args[0]
            self.red    = other_color.red
            self.green  = other_color.green
            self.blue   = other_color.blue
            self.alpha  = other_color.alpha
        else
            raise ArgumentError, "Invalid arguments for set method"
        end
    when 3 # 三个参数, 分别为 red, green, blue (alpha 默认为 255)
        self.red   = args[0]
        self.green = args[1]
        self.blue  = args[2]
        self.alpha = 255.0
    when 4 # 四个参数, 分别为 red, green, blue, alpha
        self.red   = args[0]
        self.green = args[1]
        self.blue  = args[2]
        self.alpha = args[3]
    else
        raise ArgumentError, "Invalid arguments for set method"
    end
end