How to end a math.random

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
IcE Sparkz
Prole
Posts: 2
Joined: Mon Feb 17, 2014 5:19 pm

How to end a math.random

Post 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!
User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: How to end a math.random

Post 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.
IcE Sparkz
Prole
Posts: 2
Joined: Mon Feb 17, 2014 5:19 pm

Re: How to end a math.random

Post by IcE Sparkz »

Thank you.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests