Page 1 of 1
How to end a math.random
Posted: Mon Feb 17, 2014 5:23 pm
by IcE Sparkz
Hey there guys and gals! I am wondering if anyone has a custom function or something to end a math.random function, I am currently in development of a platformer game which I am required to put a math.random in a love.graphics.rectangle() module. I am trying to get them to move at different speeds and I would appreciate the help. Thanks!
Re: How to end a math.random
Posted: Mon Feb 17, 2014 6:29 pm
by DaedalusYoung
You use a variable. Instead of something like this:
Code: Select all
function love.draw()
love.graphics.rectangle('fill', love.math.random(0, 128), 256, 64, 64)
end
Which will draw the rectangle in a new position every frame,
you do this:
Code: Select all
local xval = love.math.random(0, 128)
function love.draw()
love.graphics.rectangle('fill', xval, 256, 64, 64)
end
Which will assign a random value to
xval once and then draw the rectangle at the exact same position every frame.
Re: How to end a math.random
Posted: Mon Feb 17, 2014 6:44 pm
by IcE Sparkz
Thank you.