How can I make randomly generated multiple objects spawn on the screen?
Posted: Sun Oct 10, 2021 12:25 am
Coin = {}
function Coin:load()
self.width = 20
self.height = 20
self.speed = 200
self.x = love.math.random(0, love.graphics.getWidth() - self.width)
self.y = love.math.random(0, love.graphics.getHeight() - self.height)
end
function Coin:update(dt)
end
function Coin:draw()
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
end
So here is my current code, and if u run this code, u can just see a white square generating randomly on random pos on the screen. My goal here is to try and make multiple generating objects at random spot and then disappearing.
If u can, please help me out, I'm quite new to Lua and coding.
function Coin:load()
self.width = 20
self.height = 20
self.speed = 200
self.x = love.math.random(0, love.graphics.getWidth() - self.width)
self.y = love.math.random(0, love.graphics.getHeight() - self.height)
end
function Coin:update(dt)
end
function Coin:draw()
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
end
So here is my current code, and if u run this code, u can just see a white square generating randomly on random pos on the screen. My goal here is to try and make multiple generating objects at random spot and then disappearing.
If u can, please help me out, I'm quite new to Lua and coding.