赞 | 153 |
VIP | 10 |
好人卡 | 39 |
积分 | 93 |
经验 | 146191 |
最后登录 | 2024-5-6 |
在线时间 | 2504 小时 |
Lv4.逐梦者
- 梦石
- 0
- 星屑
- 9280
- 在线时间
- 2504 小时
- 注册时间
- 2011-5-20
- 帖子
- 15389
|
003号人 发表于 2012-6-7 16:39
这个不知道行不行 - class Game_Picture
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :number # 图片编号
- attr_reader :name # 文件名
- attr_reader :origin # 原点
- attr_reader :x # X 坐标
- attr_reader :y # Y 坐标
- attr_reader :zoom_x # X 方向放大率
- attr_reader :zoom_y # Y 方向放大率
- attr_reader :opacity # 不透明度
- attr_reader :blend_type # 合成方式
- attr_reader :tone # 色调
- attr_reader :angle # 旋转角度
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # number : 图片编号
- #--------------------------------------------------------------------------
- def initialize(number)
- @number = number
- @name = ""
- @origin = 0
- @x = 0.0
- @y = 0.0
- @zoom_x = 100.0
- @zoom_y = 100.0
- @opacity = 255.0
- @blend_type = 1
- @duration = 0
- @target_x = @x
- @target_y = @y
- @target_zoom_x = @zoom_x
- @target_zoom_y = @zoom_y
- @target_opacity = @opacity
- @tone = Tone.new(0, 0, 0, 0)
- @tone_target = Tone.new(0, 0, 0, 0)
- @tone_duration = 0
- @angle = 0
- @rotate_speed = 0
- end
- #--------------------------------------------------------------------------
- # ● 显示图片
- # name : 文件名
- # origin : 原点
- # x : X 坐标
- # y : Y 坐标
- # zoom_x : X 方向放大率
- # zoom_y : Y 方向放大率
- # opacity : 不透明度
- # blend_type : 合成方式
- #--------------------------------------------------------------------------
- def show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
- @name = name
- @origin = origin
- @x = x.to_f
- @y = y.to_f
- @zoom_x = zoom_x.to_f
- @zoom_y = zoom_y.to_f
- @opacity = opacity.to_f
- @blend_type = blend_type
- @duration = 0
- @target_x = @x
- @target_y = @y
- @target_zoom_x = @zoom_x
- @target_zoom_y = @zoom_y
- @target_opacity = @opacity
- @tone = Tone.new(0, 0, 0, 0)
- @tone_target = Tone.new(0, 0, 0, 0)
- @tone_duration = 0
- @angle = 0
- @rotate_speed = 0
- end
- #--------------------------------------------------------------------------
- # ● 移动图片
- # duration : 时间
- # origin : 原点
- # x : X 坐标
- # y : Y 坐标
- # zoom_x : X 方向放大率
- # zoom_y : Y 方向放大率
- # opacity : 不透明度
- # blend_type : 合成方式
- #--------------------------------------------------------------------------
- def move(duration, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
- @duration = duration
- @origin = origin
- @target_x = x.to_f
- @target_y = y.to_f
- @target_zoom_x = zoom_x.to_f
- @target_zoom_y = zoom_y.to_f
- @target_opacity = opacity.to_f
- @blend_type = blend_type
- end
- #--------------------------------------------------------------------------
- # ● 更改旋转速度
- # speed : 旋转速度
- #--------------------------------------------------------------------------
- def rotate(speed)
- @rotate_speed = speed
- end
- #--------------------------------------------------------------------------
- # ● 开始更改色调
- # tone : 色调
- # duration : 时间
- #--------------------------------------------------------------------------
- def start_tone_change(tone, duration)
- @tone_target = tone.clone
- @tone_duration = duration
- if @tone_duration == 0
- @tone = @tone_target.clone
- end
- end
- #--------------------------------------------------------------------------
- # ● 消除图片
- #--------------------------------------------------------------------------
- def erase
- @name = ""
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- if @duration >= 1
- d = @duration
- @x = (@x * (d - 1) + @target_x) / d
- @y = (@y * (d - 1) + @target_y) / d
- @zoom_x = (@zoom_x * (d - 1) + @target_zoom_x) / d
- @zoom_y = (@zoom_y * (d - 1) + @target_zoom_y) / d
- @opacity = (@opacity * (d - 1) + @target_opacity) / d
- @duration -= 1
- end
- if @tone_duration >= 1
- d = @tone_duration
- @tone.red = (@tone.red * (d - 1) + @tone_target.red) / d
- @tone.green = (@tone.green * (d - 1) + @tone_target.green) / d
- @tone.blue = (@tone.blue * (d - 1) + @tone_target.blue) / d
- @tone.gray = (@tone.gray * (d - 1) + @tone_target.gray) / d
- @tone_duration -= 1
- end
- if @rotate_speed != 0
- @angle += @rotate_speed / 2.0
- while @angle < 0
- @angle += 360
- end
- @angle %= 360
- end
- end
- end
复制代码 |
|