| 赞 | 289 |
| VIP | |
| 好人卡 | |
| 积分 | 85 |
| 经验 | |
| 最后登录 | 2019-7-14 |
| 在线时间 | 775 小时 |
- 梦石
- 0
- 星屑
- 8498
- 在线时间
- 775 小时
- 注册时间
- 2017-11-10
- 回帖
- 1074
|
发表于 2018-3-18 19:11:40
|
显示全部楼层
r == 6 ? r = 1 : r += 1 if Input.repeat?(:RIGHT)
r == 1 ? r = 6 : r -= 1 if Input.repeat?(:LEFT)
问号冒号表达式本来就是一种判断,不是true就是false。
再在后面加一段的判断是做什么用呢?true时判断按键还是false时判断按键?
不知道楼主的具体用意是?
- #each_with_index do 双重迭代用法。
- #例子:hash = Hash.new
- #%w(cat dog wombat).each_with_index {|item, index|
- # hash[item] = index
- #}
- #p hash
- #结果为:{"cat"=>0, "dog"=>1, "wombat"=>2}
- #item代入的是循环的内容
- #index则从0开始,循环1次+1
复制代码
看楼主的例子:
那n就是循环的内容。
i就是索引。
要拆解分行的话可以写成这样。
[pre lang="ruby"]class Window_Base < Window
#--------------------------------------------------------------------------
# ● 绘制强化/弱化状态的图标
#--------------------------------------------------------------------------
def draw_actor_icons(actor, x, y, width = 480)
icons = (actor.state_icons + actor.buff_icons)[0, width / 24]
icons.each_with_index {|n, i| draw_icon(n, x + 24 * i, y) }
if n > 16
draw_icon(n, x + 24 * i, y)
draw_icon(n+16, x + 24 * i, y + line_height * 1)
else
draw_icon(n, x + 24 * i, y)
end
end
end
class Window_BattleStatus < Window_Selectable
#--------------------------------------------------------------------------
# ● 绘制基本区域
#--------------------------------------------------------------------------
def draw_basic_area(rect, actor)
draw_actor_name(actor, rect.x + 0, rect.y, 100)
draw_actor_icons(actor, rect.x + 0, rect.y + line_height * 1, 384)
end
end[/pre] |
|