Page 1 of 1

[SOLVED] Problem with graphics.setColor

Posted: Fri Feb 22, 2013 8:38 am
by Ragerin
First of all, hello to you all!

I am having issues with using love.graphics.setColor.
In my love.draw()-function, I am drawing some images. Afterwards I want to draw a, let's say, green rectangle. But when I test my application, the entire Love-window goes green (and note, it's green transparent, even though I write 255 in alpha).

Here's my draw-function:

Code: Select all

function love.draw()
    love.graphics.draw(bgimg, 0, 0)
    love.graphics.draw(eng_bar, btn_eng.x, btn_eng.y)
    love.graphics.draw(rot_bar, btn_rot.x, btn_rot.y)
    love.graphics.draw(krot_btn_off, btn_krot.x, btn_krot.y)
    love.graphics.draw(pship, shipmarker.x, shipmarker.y, deg_to_rad(orient_deg), 1, 1, shipmarker.w/2, shipmarker.h/2)
    
    --love.graphics.setColor(0, 0, 0, 255)
    love.graphics.print("     Set Engine: "..engine_set, 10, 10)
    love.graphics.print("  Current Speed: "..engine_cur, 10, 20)
    love.graphics.print("Orientation/deg: "..orient_deg, 10, 30)
    love.graphics.print(" i : "..i, 10, 40)

    love.graphics.setColor(0, 255, 0, 255)              -- < That makes entire window green transparent?
    love.graphics.rectangle("fill", btn.x, btn.y, btn.w, btn.h)
end

Why has my code gone ill? :brows:

Re: Problem with graphics.setColor

Posted: Fri Feb 22, 2013 9:07 am
by OmarShehata
Imagine Love being an artist, a human artist. Love draws everything using one paint brush. It starts with a bucket of white paint, and it's drawing everything. Then you replace the white paint with green, so it draws your rectangle green, but it's also going to draw everything after that in green because..the bucket has green paint in it.

You need put white paint back in after you're done drawing the green rectangle.

Re: Problem with graphics.setColor

Posted: Fri Feb 22, 2013 9:12 am
by Ragerin
Thank you very much. :-) That was the problem. This clarifies a lot.