I am currently trying to create a Love2d space game, I am trying to create random generation for the stars with little luck, my function for creating the stars is :
function space.drawStars()
for i = 1, space.starNum do
love.graphics.setColor(255, 255, 255)
space.starSize = love.math.random(1, 10)
space.starXPosition = love.math.random(1, 1200)
space.starYPosition = love.math.random(1, 750)
love.graphics.rectangle("fill", space.starXPosition,space.starYPosition, space.starSize, space.starSize)
end
end
The current problem I am having with this function is that when it is ran Lua seems to run the function multiple times and the stars are constantly changing. I have tried placing the contents of this function inside the load() function in my main class but as this needs to be inside my draw function it would not generate the stars.
Please could somebody help me with how I am to make this function run only once so Lua only draws one set of stars and does not constantly keep creating new stars and destroying the original ones.
Thank you,