Project1
标题:
Sprite&Window Move To - 精灵类和窗口类的移动方法
[打印本页]
作者:
忧雪の伤
时间:
2011-5-21 12:11
标题:
Sprite&Window Move To - 精灵类和窗口类的移动方法
本帖最后由 忧雪の伤 于 2011-5-21 17:50 编辑
Sprite&Window
方法
move_to(x, y, duration)
开始移动,
x
是移动到的 X 座标,
y
是移动到的 Y 座标,
duration
是移动的帧数。
需要移动的情况下必须调用
update
方法。
例子:
sprite = [Sprite.new, Sprite.new]
sprite[0].move_to(10, 10, 10); sprite[1].move_to(10, 10, 10)
Graphics.wait(10){sprite[0].update; sprite[1].update}
print sprite[0].x, sprite[0].y # => 10, 10
print sprite[1].x, sprite[1].y # => 10, 10
复制代码
*
Graphics.wait
请参考 RGSS2 的帮助。
定义
#==============================================================================
# ** Graphics
#==============================================================================
module Graphics
#--------------------------------------------------------------------------
# * Wait
#--------------------------------------------------------------------------
unless method_defined?("wait"); def self.wait(duration)
duration.times{update; yield if defined? yield}; end; end
end
#==============================================================================
# ** Sprite
#==============================================================================
class Sprite
alias move_system_update update unless method_defined?("move_system_update")
#--------------------------------------------------------------------------
# * Move To
#--------------------------------------------------------------------------
def move_to(*args)
args[0] = args[0].round if args[0].is_a?(Float)
args[1] = args[1].round if args[1].is_a?(Float)
@move_system = [args, args[0] - self.x, args[1] - self.y, 0]
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
move_system_update
return if @move_system.nil?; @move_system[3] += 1
self.x += @move_system[1] / @move_system[0][2]
self.y += @move_system[2] / @move_system[0][2]
return unless @move_system[3] == @move_system[0][2]
self.x, self.y, @move_system = @move_system[0][0], @move_system[0][1], nil
end
end
#==============================================================================
# ** Window
#==============================================================================
class Window
alias move_system_update update unless method_defined?("move_system_update")
#--------------------------------------------------------------------------
# * Move To
#--------------------------------------------------------------------------
def move_to(*args)
args[0] = args[0].round if args[0].is_a?(Float)
args[1] = args[1].round if args[1].is_a?(Float)
@move_system = [args, args[0] - self.x, args[1] - self.y, 0]
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
move_system_update
return if @move_system.nil?; @move_system[3] += 1
self.x += @move_system[1] / @move_system[0][2]
self.y += @move_system[2] / @move_system[0][2]
return unless @move_system[3] == @move_system[0][2]
self.x, self.y, @move_system = @move_system[0][0], @move_system[0][1], nil
end
end
复制代码
作者:
1244570859
时间:
2012-12-3 18:27
抢沙发
作者:
yangff
时间:
2012-12-3 18:44
……居然是阻塞的= =|
作者:
zeldafd
时间:
2012-12-4 22:06
哇,剛好想要來做個效果,謝
作者:
ky52879
时间:
2012-12-14 16:11
经测试,非常严重的BUG,sprite的起始X坐标是0,终点坐标是10,如果移动的帧数(时间)超过10的话,此脚本无效,也就是说:
在计算坐标移动的方法中,算法不对,这种算法是初级算法,还请楼主仔细想想算法应当怎么改,呵呵。
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1