Why does my project stop when I run it?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
diamondglass
Prole
Posts: 1
Joined: Wed Mar 16, 2022 2:22 pm

Why does my project stop when I run it?

Post by diamondglass »

Why does my project stop when I run it? What do I mean? Well, because my project (it's a "screen") stops me
at the moment of executing it, I will leave the code so that they can help me to know what happens.

PD: I translate it because my English is basic

Code: Select all

function love.load()
    love.window.setMode(300,200,{resizable=false})
end

function love.draw()
	DrawDisplay(300,200)
end

function love.update()

end

function DrawDisplay(w,h)
	for y = 1, h do
		for x = 1, w do
			DrawPoint(x - 1,y,color)
		end
		y = y + 1
	end	
end

function DrawPoint(x,y,color)
	love.graphics.points(x,y)
	love.graphics.setColor(love.math.colorFromBytes(128, 234, 255))
end
User avatar
pgimeno
Party member
Posts: 3640
Joined: Sun Oct 18, 2015 2:58 pm

Re: Why does my project stop when I run it?

Post by pgimeno »

You should not draw pixel by pixel to fill the screen. OpenGL is very slow when doing that. Draw a rectangle that covers the whole area instead, like this:

Code: Select all

function DrawDisplay(w, h)
	love.graphics.setColor(love.math.colorFromBytes(128, 234, 255)
	love.graphics.rectangle("fill", 0, 0, w, h)
end
But if you want to fill the screen with a colour, you can use "love.graphics.clear()" like this:

Code: Select all

function DrawDisplay(w, h)
	love.graphics.clear(love.graphics.colorFromBytes(128, 234, 255))
end
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Why does my project stop when I run it?

Post by zorg »

I don't recall whether points are actually batched or not, but if they aren't, you might get *somewhat* better performance by drawing a tinted 1x1 white Image instead.

Code: Select all

local dot = love.graphics.newImage(love.graphics.newImageData(1,1,'rgba8',string.char(255,255,255,255)))
function DrawPoint(x,y,color)
    love.graphics.setColor(love.math.colorFromBytes(color))
    love.graphics.draw(dot, x, y)
end
You might want to also specify color somewhere... since you do want to treat it as a variable you pass around.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Google [Bot], swuare and 7 guests