How to end a math.random
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 2
- Joined: Mon Feb 17, 2014 5:19 pm
How to end a math.random
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!
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: How to end a math.random
You use a variable. Instead of something like this:
Which will draw the rectangle in a new position every frame,
you do this:
Which will assign a random value to xval once and then draw the rectangle at the exact same position every frame.
Code: Select all
function love.draw()
love.graphics.rectangle('fill', love.math.random(0, 128), 256, 64, 64)
end
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
-
- Prole
- Posts: 2
- Joined: Mon Feb 17, 2014 5:19 pm
Re: How to end a math.random
Thank you.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests