我在 RPG Maker XP(用 ruby 制作)中编写了一些动画脚本,允许您显示动态图像。我的问题不是严格意义上的 RPG Maker,而是笼统的。这是我到目前为止发现的代码,它可以工作,但是有问题:
class Poser
attr_accessor :images
def initialize
@images = Sprite.new
@images.bitmap = RPG::Cache.picture('Character.png') #display picture
@images.x = 540 #place it on the bottom right corner of the screen
@images.y = 180
end
def move(x,y)
@images.x += x
@images.y += y
end
def animate(x,y,step,delay) #Animate moving the picture up and down with delay
forward = true
2.times { #the first loop, do code 2 times of :
step.times {
wait(delay) #wait x frame
if forward
move(x/step,y/step) #move the picture down
else
move(-x/step,-y/step) #move the picture up
end
}
wait(delay*3)
forward = false
}
end
def wait(time)
while time > 0
time -= 1
Graphics.update
end
end
end
然后我创建它的一个实例并调用该方法:
$test = Poser.new
$test.animate(0,10,10,10)
上面的代码所做的就是上下移动图片(就像呼吸动画一样,你的头上下摆动)
如您所见,我使用循环函数延迟移动图片。我得到的是,在动画完成之前我不能做任何其他事情。我所说的“其他”是指与我的角色四处走动,与NPC交谈,我想在后台播放动画时做这些事情。最后,游戏在循环块中“暂停”了。
是否有另一种方法可以在不循环的情况下制作动画,或者在动画完成之前不会“暂停”屏幕的任何方法?提前致谢。