[SOLVED] Background Image? (I put if solved cause I'm nice)

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
iPoisonxL
Party member
Posts: 227
Joined: Wed Feb 06, 2013 3:53 am
Location: Australia
Contact:

[SOLVED] Background Image? (I put if solved cause I'm nice)

Post by iPoisonxL »

Hey, I'm new to Love2d, and I'm making a game, currently.
I know how to add a background image, it's possibly the simplest thing ever. The thing is, with a conditional statement (if() in this case), when I try to set a background image to a condition, it just displays a completely black screen. I've tried setting the background color to (255,255,255), and it's still a completely black background.. I'm not sure what's wrong. Here's the code for my function love.draw.

Code: Select all

function love.draw()

	if (state=='playing') then
		love.graphics.draw(hills, 0, 0)
		love.graphics.draw(player.image, player.x, player.y)
	end

	if (state=='menu') then
		button_draw()
                love.graphics.draw(menuBackground, 0, 0)
	end

end
Here is the variable.

Code: Select all

menuBackground=love.graphics.newImage('/sprites/menu.png')
And here is the code for menu.lua, what I use to make the menu functions.

Code: Select all

button={}
function button_spawn(x,y,text,id)
	table.insert(button, {x=x, y=y, text=text, id=id})
end

function button_draw()

	for i,v in ipairs(button) do
		love.graphics.setColor(0,0,0)
		love.graphics.setFont(fixedsys)
		love.graphics.print(v.text,v.x,v.y)
	end

end

function button_click(x,y)

	for i,v in ipairs(button) do

		if (x > v.x and
		x < v.x + fixedsys:getWidth(v.text) and
		y > v.y and
		y < v.y + fixedsys:getHeight()) then
			if (v.id=='quit') then
				love.event.push('quit')
			end
		end

	end

end
If you need any more of my code to find the problem, tell me. I'll happily add it.
Last edited by iPoisonxL on Fri Feb 22, 2013 12:06 am, edited 1 time in total.

Code: Select all

      L
    L Ö
    Ö V
L Ö V E
Ö B E
V E
E Y
Website
Automatik
Citizen
Posts: 57
Joined: Sun Feb 17, 2013 7:05 pm

Re: Background Image?

Post by Automatik »

Hey, welcome to the forums!(Coming from someone who just registered to reply to you :p )
  • You don't need () in a "if then" condition. you can do "if a==b then"
  • You're drawing the button, then the background. The button then can't be shown since it's under the background.
  • The menu will only be drawn if state contain "menu" . Are you sure you have something like "state="menu" " in love.init() ?
  • Later, you might want to divide your program in multiple files.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Background Image?

Post by bartbes »

Also, you set the color to 0, 0, 0, that will affect anything drawn after that, including in the next frames, therefore everything will be drawn black.
User avatar
iPoisonxL
Party member
Posts: 227
Joined: Wed Feb 06, 2013 3:53 am
Location: Australia
Contact:

Re: Background Image?

Post by iPoisonxL »

Automatik wrote:Hey, welcome to the forums!(Coming from someone who just registered to reply to you :p )
  • You don't need () in a "if then" condition. you can do "if a==b then"
  • You're drawing the button, then the background. The button then can't be shown since it's under the background.
  • The menu will only be drawn if state contain "menu" . Are you sure you have something like "state="menu" " in love.init() ?
  • Later, you might want to divide your program in multiple files.
I like to use () in the if then conditions, makes me feel special. Also, it's a good habit because I program in a lot of other languages. None of these were the answer, but thanks for trying. I found the answer myself it's because I was setting the color to 0,0,0 in menu.lua, which set the picture's color black. I did divide my program in multiple files, you just don't see them.

Code: Select all

      L
    L Ö
    Ö V
L Ö V E
Ö B E
V E
E Y
Website
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Background Image?

Post by substitute541 »

In functions when you're setting colors, it's best to reset it at the end of the function with "love.graphics.setColor(255,255,255)". It's usually what I do in my class functions.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 57 guests