Page 1 of 1
Planet Spawning, Please Help
Posted: Tue Nov 04, 2014 1:47 am
by Puzzelism
Okay, so i'm trying to make some pretty basic code to spawn some planets (also known as circles), I don't know what I'm doing that makes the drawing function not work. here is the code:
Code: Select all
math.randomseed(os.time())
planet = {}
numPlanetsMax = math.random(3, 5)
numPlanets = 0
function planet_generate(dt)
for i=1, numPlanetsMax do
if numPlanets < numPlanetsMax then
planet_load(12, 32, 54)
numPlanets = numPlanets + 1
end
end
end
function planet_load(x, y, size)
table.insert(planet, {x = x, y = y, size = size})
end
function planet_draw()
for i,v in ipairs(planet) do
love.graphics.setColor(255,255,255)
love.graphics.circle("fill", planet.x, planet.y, planet.size, planet.size)
end
end
Also here is the .love:
Re: Planet Spawning, Please Help
Posted: Tue Nov 04, 2014 2:36 am
by HugoBDesigner
It MAY be because you're making the 4th argument of love.graphics.circle as the same value as the 3rd.
In LÖVE, circles don't have different widths and heights: it's all a single variable (the 3rd argument). The 4th argument is for number of sizes of the circle (since it's not a circle properly, but a polygon with a bunch of sides - I often set it to 32).
So you'd maybe do this:
love.graphics.circle("fill", planet.x, planet.y, planet.size, 32)
Re: Planet Spawning, Please Help
Posted: Tue Nov 04, 2014 2:42 am
by Puzzelism
Thanks for the reply, tried your solution and it didn't work. I believe the problem is with argument 2 of the circle drawing. However thank you for that information, I hadn\t properly researched love.graphics.circle before hand, and i kinda understood it, thanks for the clarification
Re: Planet Spawning, Please Help
Posted: Tue Nov 04, 2014 3:27 am
by HugoBDesigner
I downloaded it, took a look at your code again and realized:
You're doing a
for loop through each item in the
planet table:
for i, v in pairs(planet) do
But you're drawing it as
planet.something, even though the
planet table contains all the planets. So, in the drawing function, replace all "planet" by "v" and it should work
Re: Planet Spawning, Please Help
Posted: Tue Nov 04, 2014 5:06 am
by Puzzelism
Thanks, figured that out like three seconds before reading this post and I felt so dumb
Anyways thanks for the help. Happy LÖVING
.
Re: Planet Spawning, Please Help
Posted: Tue Nov 04, 2014 12:17 pm
by s-ol
Also a quick hint: your planet_generate method doesn't need the dt argument! First it just doesn't fit there and second the argument isn't used anyway
Re: Planet Spawning, Please Help
Posted: Wed Nov 05, 2014 5:23 am
by Puzzelism
Thanks for all the replies, however I ran into another problem that ive been trying to solve all night. The problem here is that im trying to spawn forests, really for no reason other than for future uses, im trying to spawn them individually onto planets, however i will work on that later, as of now however im trying to just focus on variety in the forests, different colors etc. Run the .love and you will find out the new problem. Please feel free to clean up my code and judge it as much as you want, im still pretty new to this.
Love it: