循环期间的Lua更新屏幕
我正在为屏幕上的角色编写一个函数,使其遵循标记的路径。我希望遍历该角色的所有标记,并更新每个标记的显示。现在的情况是,显示只在迭代结束时更新一次。根据一些常见问题,lua似乎就是这样设计的。那么,在lua中实现渐进运动的最佳方式是什么循环期间的Lua更新屏幕,lua,Lua,我正在为屏幕上的角色编写一个函数,使其遵循标记的路径。我希望遍历该角色的所有标记,并更新每个标记的显示。现在的情况是,显示只在迭代结束时更新一次。根据一些常见问题,lua似乎就是这样设计的。那么,在lua中实现渐进运动的最佳方式是什么 local function follow_movement_path (moving_char) these_markers = moving_char.move_markers for m, n in ipairs(these_markers)
local function follow_movement_path (moving_char)
these_markers = moving_char.move_markers
for m, n in ipairs(these_markers) do
this_marker = n
moving_char.x = this_marker.x
moving_char.y = this_marker.y
print(this_marker.current_space.name)
sleep(1)
end
end
提前感谢您提供的任何见解。这是一个如何解决此问题的示例。一个有趣的方法是(或)方法。我们的想法是,您仍然可以像您的示例中那样编写代码,但在每次迭代后,您都会跳出循环,在屏幕上画图,并在您离开的确切位置继续执行该函数
可能是这样的:
local function follow_movement_path (moving_char)
these_markers = moving_char.move_markers
for m, n in ipairs(these_markers) do
this_marker = n
moving_char.x = this_marker.x
moving_char.y = this_marker.y
print(this_marker.current_space.name)
coroutine.yield()
end
end
local c = coroutine.create(follow_movement_path)
coroutine.resume(c)
draw_on_display()
coroutine.resume(c)
虽然这将需要比我预期的更多的工作来完全实现它,但它可能是Lua中可用的最佳解决方案。谢谢你的博客链接。我以前甚至不知道合作的惯例。