function love.load()
local screen_width, screen_height = love.graphics.getDimensions()
local max_stars = 100 -- how many stars we want
stars = {} -- table which will hold our stars
for i=1, max_stars do -- generate the coords of our stars
local x = love.math.random(5, screen_width-5) -- generate a "random" number for the x coord of this star
local y = love.math.random(5, screen_height-5) -- both coords are limited to the screen size, minus 5 pixels of padding
stars[i] = {x, y} -- stick the values into the table
end
end
function love.draw()
love.graphics.points(stars) -- draw all stars as points
end
Last edited by paul54000 on Tue Dec 06, 2016 3:10 pm, edited 1 time in total.
local scrollSpeed = 100
local screenWidth = love.graphics.getWidth()
function love.update(dt)
for i,v in ipairs(stars) do
v.x = v.x - scrollSpeed * dt
if(v.x < 0) then
v.x = v.x + screenWidth
end
end
end
function love.load()
local screen_width, screen_height = love.graphics.getDimensions()
local max_stars = 100 -- how many stars we want
stars = {} -- table which will hold our stars
for i=1, max_stars do -- generate the coords of our stars
local x = love.math.random(5, screen_width-5) -- generate a "random" number for the x coord of this star
local y = love.math.random(5, screen_height-5) -- both coords are limited to the screen size, minus 5 pixels of padding
stars[i] = {x, y} -- stick the values into the table
end
end
local scrollSpeed = 100
local screenWidth = love.graphics.getWidth()
function love.update(dt)
for i,v in ipairs(stars) do
v.x = v.x - scrollSpeed * dt
if(v.x < 0) then
v.x = v.x + screenWidth
end
end
end
function love.draw()
love.graphics.points(stars) -- draw all stars as points
end
Finally, this works. I assume this is what you're looking for.
Read the comments, don't just use the snippet for whatever reason. Try to learn from it!
--Global vars
totalDt = 0
stars = {} -- table which will hold our stars
screen_width, screen_height = love.graphics.getDimensions()
function love.load()
local max_stars = 500 -- how many stars we want
for i=1, max_stars do -- generate the coords of our stars
local x = love.math.random(5, screen_width-5) -- generate a "random" number for the x coord of this star
local y = love.math.random(5, screen_height-5) -- both coords are limited to the screen size, minus 5 pixels of padding
local r = 255
local g = 255 -- Set colors to white
local b = 255
local a = love.math.random()*254
stars[i] = {x, y, r, g, b, a} -- stick the values into the table
end
end
function love.update(dt)
totalDt = totalDt + dt
if totalDt >= 0.05 then --Reduce this comparison value to increase scroll speed/blink speed
screen_width, screen_height = love.graphics.getDimensions() --Gets current screen dimensions
for i, v in ipairs(stars) do
--Iterate over every star and assign a new alpha value for then
--Assign a new Y value if you want
stars[i][6] = love.math.random(60, 254)
stars[i][2] = stars[i][2] - 1
if stars[i][2] == 0 then --Wraps around screen
stars[i][1] = love.math.random(5, screen_width-5) --new X
stars[i][2] = screen_height - 5 --new Y, starting at bottom
end
end
totalDt = 0 --Reset dt time count
end
end
function love.draw()
love.graphics.points(stars) --Draws all stars on the table
end
Don't check my github! It contains thousands of lines of spaghetti code in many different languages cool software! https://github.com/Sulunia