Page 1 of 1

Background and Text

Posted: Sat Jul 05, 2008 12:37 am
by mastastealth
Right now I have a:

Code: Select all

   love.graphics.draw(bg, 320, 240)
   love.graphics.draw(mouseX, 20,20) 
   love.graphics.draw(mouseY, 20,40) 
But the text does not come up. Taking out the "bg" will show the text on a black background. Is there a way to sort the Z-order of what is drawn? Also, for a future release, would it be possible to separate Backgrounds from Sprite, and have them have separate classes?

Re: Background and Text

Posted: Sat Jul 05, 2008 1:18 am
by Merkoth
AFAIK, it's supposed to respect the order you use (first thing to be draw()ed will appear "under" the rest), so your code should work without problems.

Actually, I can't replicate the problem with LÖVE 0.3.2 (Ubuntu Hardy):

Image
Image

Code: Select all

function load()

    image = love.graphics.newImage("test.png")
    font = love.graphics.newFont(love.default_font, 24)
    love.graphics.setFont(font)
    love.graphics.setColor(255,255,255)
end

function update(dt)
end

function draw()
    
    love.graphics.draw(image, 320, 240)
    love.graphics.draw("Test", 10, 50)
    love.graphics.draw("Another test", 10, 100)
end
So, you code should work as expected, maybe you've hit a bug?

PS: ¡Alguien que puede entender español! :D (Someone who can understand spanish!)

Re: Background and Text

Posted: Sat Jul 05, 2008 1:39 am
by mastastealth
:lol: Man, I'm such a noob. The problem was the white background I was using, since it seems the text is rendered white on deafult. :? Is there a way to change the font color? :P

(Yup, hablo español, pero prefiero el Ingles. ;))

Re: Background and Text

Posted: Sat Jul 05, 2008 1:58 am
by cag
The color setting function in graphics sets the color to be used for all graphics functions (even the ones that draw images, I believe!). Noting that:

Code: Select all

   love.graphics.setColor(255, 255, 255)
   love.graphics.draw(bg, 320, 240)
   love.graphics.setColor(0, 0, 0)
   love.graphics.draw(mouseX, 20,20)
   love.graphics.draw(mouseY, 20,40)

Re: Background and Text

Posted: Sat Jul 05, 2008 2:00 am
by Merkoth
Yes you can, just call love.graphics.setColor(). You have a few choices:

1) Use a Color object like this:

Code: Select all

-- create the color
color = love.graphics.newColor( red, green, blue, alpha )

-- and then call setColor
love.graphics.setColor(color)

-- and draw stuff
2) Use setColor directly (as I did in my previous example, without specifying alpha, though):

Code: Select all

love.graphics.setColor(red,green,blue,alpha)
-- and draw whatever you want
Please note that setColor affects both fonts and primitives, you should call it before drawing stuff, using whatever color you want. Using the previous example, if change:

Code: Select all

love.graphics.draw("Test", 10, 50)
love.graphics.draw("Another test", 10, 100)
to

Code: Select all

love.graphics.draw("Test", 10, 50)
love.graphics.setColor(255,0,0)
love.graphics.draw("Another test", 10, 100)
Then you'll see "Another test" drawn in red color.

Given time, newbies evolve in talented programmers :D

EDIT: Christ, shouldn't phpBB tell me that someone beat me to it? :?

Re: Background and Text

Posted: Sat Jul 05, 2008 2:41 am
by cag
It's fine, yours went in more depth anyways. :)