赞 | 59 |
VIP | 321 |
好人卡 | 140 |
积分 | 66 |
经验 | 179075 |
最后登录 | 2024-6-19 |
在线时间 | 1275 小时 |
Lv4.逐梦者 (版主) 百合控
- 梦石
- 0
- 星屑
- 6643
- 在线时间
- 1275 小时
- 注册时间
- 2013-8-21
- 帖子
- 3657
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 余烬之中 于 2014-3-9 15:23 编辑
写脚本的时候常常需要动态移动窗口,每次都要重来很烦的有木有!
于是提高可重用性………………这个不是重点!
这是做好后用来测试的东西 莫名其妙戳中了笑点
@晴兰 @taroxd @无脑之人
附 操作方法:
脚本
module Smomo module Kit @@register = { dynamical_move: [] } # @@register module_function def register @@register end end # Smomo::Kit module_function def dynamical_move(aim, x = :x, y = :y) reg = Smomo::Kit.register[:dynamical_move] id = aim.object_id return reg[id] if reg[id] reg[id] = Object.new # class << reg[id] class << reg[id] attr_accessor :moving,:ox,:oy,:ax,:ay,:x,:y,:aim_id,:duration,:rx,:ry # moveto def moveto(tx, ty, duration) unless moving a = ObjectSpace._id2ref(@aim_id) @ox, @oy = a.send(@x), a.send(@y) @ax, @ay = tx, ty @rx, @ry = *[@ox, @oy].collect(&:to_f) @duration = duration @moving = true end _moveto end # _moveto def _moveto a = ObjectSpace._id2ref(@aim_id) @rx += (@ax - @ox).to_f / @duration @ry += (@ay - @oy).to_f / @duration a.instance_eval %! self.#{@x} = #{@rx} self.#{@y} = #{@ry} ! stop if (@rx - @ax).to_i == 0 && (@ry - @ay).to_i == 0 end # stop define_method(:stop){@moving = false} # apos define_method(:apos){[@ax, @ay]} # opos define_method(:opos){[@ox, @oy]} end # class << reg[id] reg[id].moving, reg[id].x, reg[id].y, reg[id].aim_id = false, x, y, id reg[id] end # dynamical_move end # Smomo
module Smomo
module Kit
@@register = {
dynamical_move: []
} # @@register
module_function
def register
@@register
end
end # Smomo::Kit
module_function
def dynamical_move(aim, x = :x, y = :y)
reg = Smomo::Kit.register[:dynamical_move]
id = aim.object_id
return reg[id] if reg[id]
reg[id] = Object.new
# class << reg[id]
class << reg[id]
attr_accessor :moving,:ox,:oy,:ax,:ay,:x,:y,:aim_id,:duration,:rx,:ry
# moveto
def moveto(tx, ty, duration)
unless moving
a = ObjectSpace._id2ref(@aim_id)
@ox, @oy = a.send(@x), a.send(@y)
@ax, @ay = tx, ty
@rx, @ry = *[@ox, @oy].collect(&:to_f)
@duration = duration
@moving = true
end
_moveto
end
# _moveto
def _moveto
a = ObjectSpace._id2ref(@aim_id)
@rx += (@ax - @ox).to_f / @duration
@ry += (@ay - @oy).to_f / @duration
a.instance_eval %!
self.#{@x} = #{@rx}
self.#{@y} = #{@ry}
!
stop if (@rx - @ax).to_i == 0 && (@ry - @ay).to_i == 0
end
# stop
define_method(:stop){@moving = false}
# apos
define_method(:apos){[@ax, @ay]}
# opos
define_method(:opos){[@ox, @oy]}
end # class << reg[id]
reg[id].moving, reg[id].x, reg[id].y, reg[id].aim_id = false, x, y, id
reg[id]
end # dynamical_move
end # Smomo
测试脚本
def test $adasdasdaf ||= [] ssssssss = $adasdasdaf.size $adasdasdaf[ssssssss] = Window_Base.new(424 * rand, 206 * rand, 120, 210) class << $adasdasdaf[ssssssss] alias :old_update :update def update Smomo.dynamical_move(self).moveto(424 * rand, 206 * rand, 60 * rand) old_update end end $adasdasdaf[ssssssss + 1] = Window_Base.new(394 * rand, 356 * rand, 150, 60) class << $adasdasdaf[ssssssss + 1] alias :old_update :update def update Smomo.dynamical_move(self).moveto(394 * rand, 356 * rand, 30 * rand) old_update end end $game_variables[1] += 1 end class Scene_Map alias :woyisangxinbingkuang :update def update woyisangxinbingkuang $adasdasdaf.each_with_index{|w, i| w.disposed? ? [$adasdasdaf[i] = nil, $adasdasdaf.compact!] : w.update } if $adasdasdaf end end
def test
$adasdasdaf ||= []
ssssssss = $adasdasdaf.size
$adasdasdaf[ssssssss] = Window_Base.new(424 * rand, 206 * rand, 120, 210)
class << $adasdasdaf[ssssssss]
alias :old_update :update
def update
Smomo.dynamical_move(self).moveto(424 * rand, 206 * rand, 60 * rand)
old_update
end
end
$adasdasdaf[ssssssss + 1] = Window_Base.new(394 * rand, 356 * rand, 150, 60)
class << $adasdasdaf[ssssssss + 1]
alias :old_update :update
def update
Smomo.dynamical_move(self).moveto(394 * rand, 356 * rand, 30 * rand)
old_update
end
end
$game_variables[1] += 1
end
class Scene_Map
alias :woyisangxinbingkuang :update
def update
woyisangxinbingkuang
$adasdasdaf.each_with_index{|w, i|
w.disposed? ? [$adasdasdaf[i] = nil, $adasdasdaf.compact!] : w.update
} if $adasdasdaf
end
end
然后在地图上新建事件 事件内容为执行脚本
【test】
然后进入游戏按空格疯狂地触发事件~~
当然 既然disable了…………
|
|