Background and Text

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
User avatar
mastastealth
Prole
Posts: 30
Joined: Thu Jul 03, 2008 2:44 am
Location: Barranquilla, Colombia
Contact:

Background and Text

Post 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?
User avatar
Merkoth
Party member
Posts: 186
Joined: Mon Feb 04, 2008 11:43 pm
Location: Buenos Aires, Argentina

Re: Background and Text

Post 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!)
User avatar
mastastealth
Prole
Posts: 30
Joined: Thu Jul 03, 2008 2:44 am
Location: Barranquilla, Colombia
Contact:

Re: Background and Text

Post 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. ;))
User avatar
cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

Re: Background and Text

Post 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)
User avatar
Merkoth
Party member
Posts: 186
Joined: Mon Feb 04, 2008 11:43 pm
Location: Buenos Aires, Argentina

Re: Background and Text

Post 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? :?
User avatar
cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

Re: Background and Text

Post by cag »

It's fine, yours went in more depth anyways. :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 11 guests