Drawing a image from a for loop?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Drawing a image from a for loop?

Hey, I'm trying to use love.graphics.draw entirely with table data.

Code: Select all

for k,v in pairs(buttons) do
g.draw(v.pic, v.x, v.y)
end
And here is the table.

Code: Select all

buttons = {

["Start"] = {x = 250, y = 350, width = 100, height = 50, pic = img_btnStart, picClick = img_btnStart_click, click = false, state = 0}

}
It seems so simple but I can't figure it out haha.

veethree
Inner party member
Posts: 820
Joined: Sat Dec 10, 2011 7:18 pm

Re: Drawing a image from a for loop?

Could you post all your code? would make helping you easier.

First, In the loop you call g.draw, Isn't it supposed to be v.draw? 2nd, Is the draw method even defined?

And third, what exactly is the problem, Are you getting an error?

WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Drawing a image from a for loop?

No error, the g.draw is love.graphics.draw, my apologies for not specifying that. And this is the only code other than just love.draw ' ing it that pretains to this code.

Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

Re: Drawing a image from a for loop?

Code: Select all

g = love.graphics
img_btnStart = gfx.newImage("test.png")

buttons = {
["Start"] = {x = 250, y = 350, width = 100, height = 50, pic = img_btnStart, picClick = img_btnStart_click, click = false, state = 0}
}

function love.draw()
for k,v in pairs(buttons) do
g.draw(v.pic, v.x, v.y)
end
end
It seems to work for me; just plop a test.png in the folder you're working with (or check out muh .love! )

I have a suspicion that you forgot to include the love.draw() function, or put the g.draw call in the wrong place. Drawing stuff is only possible in love.draw!
Attachments
Meow.love
Sometimes I meow
"Bump." -CMFIend420

WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Drawing a image from a for loop?

Whoops crud sorry there is an error.

incorrect parameter type : expected userdata. on the line with g.draw ...

WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Drawing a image from a for loop?

Whoops crud sorry there is an error.

incorrect parameter type : expected userdata. on the line with g.draw ...

Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Drawing a image from a for loop?

Listen, OP, please just upload a .love, because now we're kinda fishing in the dark.

WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Drawing a image from a for loop?

I'm using love 0.8.0. Here is the .love. menu.lua is where the errors are.
Attachments
LOVE Game.love

veethree
Inner party member
Posts: 820
Joined: Sat Dec 10, 2011 7:18 pm

Re: Drawing a image from a for loop?

You're calling "LOAD_BUTTONS()" where the button picture is defined before you load the image in love.load, So buttons["start"].pic is nil.

jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am