查看: 3062|回复: 3

[随意闲聊] 【卖萌第四弹】一起来写UI吧

[复制链接]
梦石
0
星屑
76
在线时间
1379 小时
注册时间
2012-7-5
回帖
1643

开拓者

发表于 2015-1-1 16:30:44 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
0.gif
(不是指MVC之类完整的"UI"概念, 只是按内建Window类的原理创建任意大小的窗口背景图, 还请各位大触不要在UI概念上触窝)
正确的食用姿势
  1. def Color.sample(alpha=255)
  2.   Color.new([0,120,255][rand(3)],[0,120,255][rand(3)],[0,120,255][rand(3)],alpha)
  3. end
  4. def sp(*args)
  5.   s = Sprite.new
  6.   b = Bitmap.new(*args)
  7.   yield b if block_given?
  8.   s.bitmap = b
  9.   return s
  10. end
  11. def rgss_run(*objs)
  12.   loop do
  13.     Graphics.update
  14.     Input.update
  15.     objs.each(&:update)
  16.   end
  17. end
  18. class M_M
  19.   attr_accessor :x, :y, :width, :height
  20.   def initialize
  21.     [url=home.php?mod=space&uid=90764]@hash[/url] = get_pieces(Bitmap.new("Resources/title_line.png"),12,198,34,56)
  22.   end
  23.   def update
  24.     update_positions
  25.     if Input.trigger?(Input::C)
  26.       @x = rand 320
  27.       @y = rand 240
  28.       @width = rand 480
  29.       [url=home.php?mod=space&uid=291977]@height[/url] = rand 320
  30.     end
  31.   end
  32.   def update_positions
  33.     w0 = @width-@hash[:corner0].bitmap.width-@hash[:corner1].bitmap.width
  34.     h0 = @height-@hash[:corner0].bitmap.height-@hash[:corner2].bitmap.height
  35.     @hash[:corner0].x += dynamic_distance(@x, @hash[:corner0].x, 7)
  36.     @hash[:corner0].y += dynamic_distance(@y, @hash[:corner0].y, 7)
  37.     @hash[:side0].src_rect.width += dynamic_distance(
  38.       w0,@hash[:side0].src_rect.width,7)
  39.     @hash[:side1].src_rect.height += dynamic_distance(
  40.       h0,@hash[:side1].src_rect.height,7)
  41.     @hash[:side2].src_rect.height += dynamic_distance(
  42.       h0,@hash[:side2].src_rect.height,7)
  43.     @hash[:side3].src_rect.width += dynamic_distance(
  44.       w0,@hash[:side3].src_rect.width,7)
  45.     @hash[:back].src_rect.width += dynamic_distance(
  46.       w0,@hash[:back].src_rect.width,7)
  47.     @hash[:back].src_rect.height += dynamic_distance(
  48.       h0,@hash[:back].src_rect.height,7)
  49.     w1 = @hash[:corner0].bitmap.width
  50.     w2 = @hash[:side0].src_rect.width+w1
  51.     h1 = @hash[:corner0].bitmap.height
  52.     h2 = @hash[:side1].src_rect.height+h1
  53.     @hash[:corner1].x = @hash[:corner0].x + w2
  54.     @hash[:corner2].x = @hash[:corner0].x
  55.     @hash[:corner3].x = @hash[:corner0].x + w2
  56.     @hash[:corner1].y = @hash[:corner0].y
  57.     @hash[:corner2].y = @hash[:corner0].y + h2
  58.     @hash[:corner3].y = @hash[:corner0].y + h2
  59.     @hash[:side0].x = @hash[:corner0].x + w1
  60.     @hash[:side1].x = @hash[:corner0].x
  61.     @hash[:side2].x = @hash[:corner0].x + w2
  62.     @hash[:side3].x = @hash[:corner0].x + w1
  63.     @hash[:side0].y = @hash[:corner0].y
  64.     @hash[:side1].y = @hash[:corner0].y + h1
  65.     @hash[:side2].y = @hash[:corner0].y + h1
  66.     @hash[:side3].y = @hash[:corner0].y + h2
  67.     @hash[:back].x = @hash[:corner0].x + w1
  68.     @hash[:back].y = @hash[:corner0].y + h1
  69.   end
  70.   def set(x, y, w, h)
  71.     @x, @y, @width, @height = x, y, w, h
  72.   end
  73.   def get_pieces(bitmap, x1, x2, y1, y2)
  74.     w, h = bitmap.width, bitmap.height
  75.     return {
  76.       :back    => miao(bitmap, Rect.new(x1,y1,x2-x1,y2-y1), 640, 480), # 中间
  77.       :corner0 => miao(bitmap, Rect.new( 0, 0,   x1,   y1),  x1,  y1), # 左上
  78.       :corner1 => miao(bitmap, Rect.new(x2, 0, w-x2,   y1),w-x2,  y1), # 右上
  79.       :corner2 => miao(bitmap, Rect.new( 0,y2,   x1, h-y2),  x1,h-y2), # 左下
  80.       :corner3 => miao(bitmap, Rect.new(x2,y2, w-x2, h-y2),w-x2,h-y2), # 右下
  81.       :side0   => miao(bitmap, Rect.new(x1, 0,x2-x1,   y1), 640,  y1), # 上部
  82.       :side1   => miao(bitmap, Rect.new( 0,y1,   x1,y2-y1),  x1, 480), # 左部
  83.       :side2   => miao(bitmap, Rect.new(x2,y1, w-x2,y2-y1),w-x2, 480), # 右部
  84.       :side3   => miao(bitmap, Rect.new(x1,y2,x2-x1, h-y2), 640,h-y2), # 下部
  85.     }
  86.   end
  87.   def miao(*args)
  88.     return new_sprite(pick_bitmap(*args))
  89.   end
  90.   def new_sprite(bitmap)
  91.     s = Sprite.new
  92.     s.bitmap = bitmap
  93.     s.z = 2333333
  94.     return s
  95.   end
  96.   def pick_bitmap(bitmap, src_rect, w, h)
  97.     b = Bitmap.new w, h
  98.     b.stretch_blt b.rect, bitmap, src_rect
  99.     return b
  100.   end
  101.   # a 目标值 b 基础值 c 速度的倒数【啥
  102.   def dynamic_distance(a, b, c)
  103.     (a - b).abs < c ? (a - b) == 0 ? 0 : (a - b).abs / (a - b) : (a - b) / c
  104.   end
  105. end

  106. m = M_M.new
  107. m.x = m.y = m.width = m.height = 200
  108. sp(640, 480){|b| b.fill_rect b.rect, Color.sample }

  109. rgss_run m
复制代码

资源:
title_line.png


喵喵喵~

评分

参与人数 1星屑 +90 收起 理由
进击の虎叔 + 90

查看全部评分


  -fk: -azogi:
梦石
0
星屑
60
在线时间
936 小时
注册时间
2008-2-14
回帖
930

开拓者

发表于 2015-1-1 16:47:14 | 显示全部楼层
滑动的效果非常流畅也很自然~看起来很舒服

评分

参与人数 1星屑 +2 收起 理由
kuerlulu + 2 断电阿姨喵~

查看全部评分

接稿,UI(已接)/立绘(已接)
无偿/有偿皆可,有偿速度会更快^q^
作品请见相册,有意请发私信:)
回复

使用道具 举报

梦石
0
星屑
9292
在线时间
2504 小时
注册时间
2011-5-20
回帖
14521

开拓者

发表于 2015-1-1 16:52:21 | 显示全部楼层
不知道颜色能不能直接用脚本改···

点评

噗  发表于 2015-1-1 16:54
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复

使用道具 举报

…あたしは天

梦石
0
星屑
2311
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2015-1-1 16:55:04 | 显示全部楼层
本帖最后由 taroxd 于 2015-1-1 16:57 编辑

109行那货不会被GC干掉么

↓ 当然不可能立即干掉的,又没有开 stress 模式

点评

不会呀, 虽然我没用变量赋值, 但是背景确实在那没有消失  发表于 2015-1-1 16:56
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部