Page 1 of 2

Black Screen.[Solved]

Posted: Tue Oct 11, 2011 3:01 pm
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++

Re: Black Screen.

Posted: Tue Oct 11, 2011 3:22 pm
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.

Re: Black Screen.

Posted: Tue Oct 11, 2011 3:40 pm
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.

Re: Black Screen.

Posted: Tue Oct 11, 2011 3:56 pm
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.)

Re: Black Screen.

Posted: Tue Oct 11, 2011 5:02 pm
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.

Re: Black Screen.

Posted: Tue Oct 11, 2011 5:23 pm
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"].

Re: Black Screen.[Solved]

Posted: Tue Oct 11, 2011 5:43 pm
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

Re: Black Screen.[Solved]

Posted: Tue Oct 11, 2011 6:00 pm
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).

Re: Black Screen.[Solved]

Posted: Tue Oct 11, 2011 6:47 pm
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++?

Re: Black Screen.[Solved]

Posted: Tue Oct 11, 2011 7:03 pm
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.