local maxX = 800
local maxZ = 600
-- veribles for the movement of the drawing
local x = 1
local z = 1
-- veribles for the color function
local red = 255
local green = 0
local blue = 0
local alpha = 255
function love.load() -- loads the window
love.window.setMode(maxX, maxZ, {resizable=false, vsync=false, minwidth=400, minheight=300})
end
function color() -- function used when drawing
red = red
green = green
blue = blue
alpha = 255
return red, green, blue, alpha
end
function rectangle() -- function used when drawing a shape
local shape = "fill"
x = x
z = z
local sizeX = 10
local sizeY = 10
return shape, x, z, sizeX, sizeY
end
local clock = os.clock
function sleep(n) -- seconds
local t0 = clock()
while clock() - t0 <= n do end
end
function love.draw()
love.graphics.setColor(color())
love.graphics.rectangle(rectangle())
end
function Xmove()
if x == maxX then
x = 1
z = z + 1
else
x = x + 1
end
end
function draw()
for i = 1, 500 do
love.draw()
Xmove()
end
end
--Game start here
love.load()
draw()
Yes. Don't call love.load() and love.draw() manually. love.load() will be called automatically when the game starts, love.draw() will be called automatically when you should draw something. Remove the last two lines, and do the things that you do in draw() in love.draw() instead.
To expand on grump's answer a little: The game loop (where love.load, love.draw, love.update, etc get called) is actually defined in the love.run function. If you don't make a love.run function, a sensible default is provided for you (check it out on the wiki). So if you're just using the default, love will call love.load exactly once at the start of the game and then call love.draw and love.update once every frame. No need for you to call them after defining them.
function love.load()
-- Initialize some stuff
-- I think you should put your x, y, red, etc... things here.
end
-- Correction 1: Your Xmove() should work like this. Not in draw()
function Xmove()
end
function love.update(dt)
Xmove()
end
-- Correction 2: This is how these two functions should work. Your code got it backwards
function draw()
-- Draw your rectangles
end
function love.draw()
draw()
end
-- Correction 3: You don't do any of these bottom lines anymore. Just remove them from your code
love.load()
love.draw()