Project1

标题: 求解一段脚本 [打印本页]

作者: 嚴子    时间: 2010-11-12 19:54
标题: 求解一段脚本
  1. class Bitmap
  2.   def draw_text2(x, y, width, height, text, align = 0)
  3.     case align
  4.     when 0 then y = 0
  5.     when 1 then y = (self.height - height) / 2
  6.     when 2 then y = self.height - height - 10
  7.     end
  8.     y = 0 if align > 2
  9.     if text.nil? then return end
  10.     for i in 0..text.length / 3
  11.       self.draw_text(x, i * self.font.size + y, 32, 32, text[i * 3, 3])
  12.     end
  13.   end
  14. end
复制代码
请教这是什么意思?
作者: fux4    时间: 2010-11-12 20:16
回复 嚴子 的帖子
  1. class Bitmap
  2.   def draw_text2(x, y, width, height, text, align = 0)#定义描绘字符方法
  3.     case align  #对对齐方式做出判断
  4.     when 0 then y = 0  #当居中时 Y = 0
  5.     when 1 then y = (self.height - height) / 2 #当左对齐时Y = 自己高度-传递高度 / 2
  6.     when 2 then y = self.height - height - 10  #同理
  7.     end
  8.     y = 0 if align > 2   #如果对齐方式大于2
  9.     if text.nil? then return end   #如果文本为空则返回空值
  10.     for i in 0..text.length / 3  #历遍所有字
  11.       self.draw_text(x, i * self.font.size + y, 32, 32, text[i * 3, 3])  #描绘
  12.     end
  13.   end
  14. end
复制代码

作者: 嚴子    时间: 2010-11-12 20:23
谢谢




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1