Black Screen.[Solved]

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.
Thief3
Prole
Posts: 5
Joined: Tue Oct 11, 2011 2:26 pm

Black Screen.[Solved]

Post by Thief3 »

When ever I attempt to run this code (as a test):

Code: Select all

function love.load()
love.graphics.setMode(860,640, false, true, 0)

love.graphics.setCaption("Black Screen")
image = love.graphics.newImage("BlockTemplate(32x32).png")

block={}
end

function love.update()
for i=0,10 do
	block.i={}
	block.i.y= 32*i
	block.i.x= 32*i
	end
	end

function love.draw()
for i=0,10 do
	love.graphics.draw(image,block.i.x,block.i.y,0, 0, 0, 0, 0)

	end
	end

	love.load()
	love.update()
	love.draw()

by draging the folder the 'main.lua' and my image are in on to the love.exe it runs put comes up with a black screen, but no error. By the way I am running on a Windows box as my Linux box is down. :( Thanks in advance.

Note:I have had around a years of pain with C and mostly C++
Last edited by Thief3 on Tue Oct 11, 2011 4:01 pm, edited 1 time in total.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Black Screen.

Post by Taehl »

Okay, a few problems I see in your code...

1) Your code indentation is strange and hard to read. <.<
2) By putting that code in love.update, it's getting called every single frame. What you seem to be trying to do is to make a little layout of blocks. Something like that you only need to run once, so it'd be better put in love.load.
3) The code you have in love.update probably isn't doing what you think it is. I imagine that you wanted to make 11 blocks, right? Well, what that code does is set the variables of /one/ block 11 times. You probably want to be storing your blocks in a table.
4) In love.graphics.draw, you tell it to draw your one block at a scale of 0... So you can't see it.
5) You don't need to call love.load, love.update, and love.draw at the end - Love itself does that.

I hope that helps. Welcome to the Love Club.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Black Screen.

Post by Robin »

When you say block.i you mean block.

What's more, you should remove all those extra arguments to love.graphics.draw. You set the scale to 0, which means it draws the image on a rectangle of 0x0 --- invisible.
Help us help you: attach a .love.
Thief3
Prole
Posts: 5
Joined: Tue Oct 11, 2011 2:26 pm

Re: Black Screen.

Post by Thief3 »

1)Yeah I get that often. Really should have neatened it up. :oops:
2)Yeah I am trying to make a small set of blocks in a diagonal setup.
3)I think I understood that, and if I did I was not trying to make 11 blocks but I was trying to do is make a table called block and then have a block.1 table with x and y variables in it ,then the same with block.2 etc with i repersenting 1 and 2.
4)...I am a true idiot. :oops:
5) Thanks for that, had no idea.

I can now move my image across the screen although very fast.Any way of having all copies of the image on the screen.

And to your last comment I do feel welcomed.especially with the speed you responded. All in all thanks.

EDIT: After seeing your post Robin I have got it to work,although I thought it did not matter if you use.i or. Either way thank you to you both. Guess i have a lot to learn about Lua( a much better language than C++ ) and Love(which beats SDL.)
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Black Screen.

Post by T-Bone »

Thief3 wrote:1)Yeah I get that often. Really should have neatened it up. :oops:
2)Yeah I am trying to make a small set of blocks in a diagonal setup.
3)I think I understood that, and if I did I was not trying to make 11 blocks but I was trying to do is make a table called block and then have a block.1 table with x and y variables in it ,then the same with block.2 etc with i repersenting 1 and 2.
4)...I am a true idiot. :oops:
5) Thanks for that, had no idea.

I can now move my image across the screen although very fast.Any way of having all copies of the image on the screen.

And to your last comment I do feel welcomed.especially with the speed you responded. All in all thanks.

EDIT: After seeing your post Robin I have got it to work,although I thought it did not matter if you use.i or. Either way thank you to you both. Guess i have a lot to learn about Lua( a much better language than C++ ) and Love(which beats SDL.)

Show us what you have now, and we'll recommend further improvements.

About indentation, the code you posted first should be written as

Code: Select all

function love.load()
	love.graphics.setMode(860,640, false, true, 0)
	love.graphics.setCaption("Black Screen")
	image = love.graphics.newImage("BlockTemplate(32x32).png")
	block={}
end

function love.update()
	for i=0,10 do
		block.i={}
		block.i.y= 32*i
		block.i.x= 32*i
	end
end

function love.draw()
	for i=0,10 do
		love.graphics.draw(image,block.i.x,block.i.y,0, 0, 0, 0, 0)
	end
end

love.load()
love.update()
love.draw()
And use tabs instead of spaces, if you don't already.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Black Screen.

Post by Robin »

Thief3 wrote:I thought it did not matter if you use.i or.

To be precise, something.hello is the same as something["hello"].
Help us help you: attach a .love.
Thief3
Prole
Posts: 5
Joined: Tue Oct 11, 2011 2:26 pm

Re: Black Screen.[Solved]

Post by Thief3 »

Code: Select all

function love.load()

	love.graphics.setMode(860,640, false, true, 0)

	love.graphics.setCaption("Black Screen")

	image = love.graphics.newImage("BlockTemplate(32x32).png")

	block={}



	for i=0,10 do

		block[i]={}
		block[i].y= 32*i
		block[i].x= 32*i

	end

end

function love.draw()

	for i=0,9 do

		love.graphics.draw(image,block[i].x,block[i].y,0, 1, 1)

	end

end
My new code, T-Bone and that makes perfect sense Robin
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Black Screen.[Solved]

Post by tentus »

Thief3 wrote:

Code: Select all

function love.load()

	love.graphics.setMode(860,640, false, true, 0)

	love.graphics.setCaption("Black Screen")

	image = love.graphics.newImage("BlockTemplate(32x32).png")

	block={}



	for i=0,10 do

		block[i]={}
		block[i].y= 32*i
		block[i].x= 32*i

	end

end

function love.draw()

	for i=0,9 do

		love.graphics.draw(image,block[i].x,block[i].y,0, 1, 1)

	end

end
My new code, T-Bone and that makes perfect sense Robin
You might want to revise your code like this:

Code: Select all

function love.load()
	love.graphics.setMode(860,640, false, true, 0)
	love.graphics.setCaption("Black Screen")
	image = love.graphics.newImage("BlockTemplate(32x32).png")
	block={}
	for i=1,10 do
		block[i]={}
		block[i].y= 32*i - 32
		block[i].x= 32*i - 32
	end
end

function love.draw()
	for i=1, #block do
		love.graphics.draw(image, block[i].x, block[i].y, 0, 1, 1)
	end
end
Generally speaking, indexes starting at 1 will make your life easier, at least in Love. Once you do that, #block is a way of getting the number of entries in your block table, that way you don't have a rendering discrepancy (your previous for loops differed).
Kurosuke needs beta testers
Thief3
Prole
Posts: 5
Joined: Tue Oct 11, 2011 2:26 pm

Re: Black Screen.[Solved]

Post by Thief3 »

Yeah I guess i should start arrays with 1 but c++ is still in my head. Also I've made it zig-zagy(for lack of a better phrase.)I going to try and make a SRPG style level editor now(a simple one).

For any body who wants to view my new code(I just realised i never mentioned I am using 32x32 squares to make my blocks):

Code: Select all

function love.load()

	love.graphics.setBackgroundColor( 255, 255, 255)

	love.graphics.setMode(860,640, false, true, 0)

	love.graphics.setCaption("Black Screen")

	image = love.graphics.newImage("BlockTemplate(good version)(32x32).png")

	tips=true

	block={}



	for i=0,10 do

		block[i]={}

		if i==0 then
			block[i].y= 1
			block[i].x= 1

		elseif i~=0 then
			k=i-1
			if tips==true then

		--Right
				block[i].y= block[k].y +8
				block[i].x= block[k].x +14

				tips=false

			elseif tips==false then

				block[i].y=block[k].y + 8
				block[i].x=block[k].x - 14
				tips=true

			end

		end

	end

end

function love.draw()

	for i=0,9 do

		love.graphics.draw(image,block[i].x,block[i].y,0, 1,1)
		love.graphics.draw(image,100,100,0,1,1)
		love.graphics.draw(image,110,109,0,1,1)
	end

end
Oh and thanks for telling about #. Do you know something like that in C++?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Black Screen.[Solved]

Post by Robin »

if bla == true then can usually be replaced by if bla then.
Likewise, if bla == false then can usually be replaced by if not bla then.
Thief3 wrote:Oh and thanks for telling about #. Do you know something like that in C++?
Vector::size() or something like that maybe? (It's been a long time...)
Also comparable to strlen for C-strings.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 8 guests