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.
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+.
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.
1)Yeah I get that often. Really should have neatened it up.
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.
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.)
Thief3 wrote:1)Yeah I get that often. Really should have neatened it up.
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.
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
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.
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
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
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).
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):
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++?