0
我试图随机生成一个随机数,每个随机秒(最终目的是随时改变块的颜色)。生成一个随机数,但每个随机数在LUA/Love2d
为此,我使用驼峰库(http://vrld.github.io/hump/#hump.timer)。
这里是我的代码,我是真正的初学者在LUA/Love2d编码。 它会生成一个数字,并且每秒显示一次,而不是每个随机秒数(但也会生成随机秒数)。 我不明白为什么它不起作用。
local Timer = require "timer"
function love.load()
text="t"
number2=1
end
local f = function()
math.randomseed(os.time())
number = math.random(2,10)
text="in " .. number2 .. " seconds (random)... random number =" .. number
return true
end
function love.update(dt)
number2 = math.random(2,4)
Timer.update(number2)
Timer.addPeriodic(number2, f)
end
function love.draw()
love.graphics.print(text, 330, 300)
end
感谢您的帮助!
在程序中调用'math.randomseed(os.time())'一次。 – lhf
我的不好,我删除了love.update中的那个,但问题依然存在。 – hycday
在更新的代码中,您仍然在'love.update'中调用'f',这意味着'math.randomseed'仍然被调用多次。 –