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
Before you make a thread asking for help, read this.
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Drawing a image from a for loop?

Post by WolfNinja2 »

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.
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: Drawing a image from a for loop?

Post by veethree »

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?
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Drawing a image from a for loop?

Post by WolfNinja2 »

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. :P
User avatar
Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

Re: Drawing a image from a for loop?

Post by Helvecta »

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! :awesome: )

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! :neko:
Attachments
Meow.love
Sometimes I meow
(2.2 KiB) Downloaded 253 times
"Bump." -CMFIend420
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Drawing a image from a for loop?

Post by WolfNinja2 »

Whoops crud sorry there is an error.

incorrect parameter type : expected userdata. on the line with g.draw ...
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Drawing a image from a for loop?

Post by WolfNinja2 »

Whoops crud sorry there is an error.

incorrect parameter type : expected userdata. on the line with g.draw ...
User avatar
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?

Post by Robin »

Listen, OP, please just upload a .love, because now we're kinda fishing in the dark.
Help us help you: attach a .love.
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Drawing a image from a for loop?

Post by WolfNinja2 »

I'm using love 0.8.0. Here is the .love. menu.lua is where the errors are.
Attachments
LOVE Game.love
(448.85 KiB) Downloaded 269 times
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: Drawing a image from a for loop?

Post by veethree »

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

Re: Drawing a image from a for loop?

Post by jjmafiae »

Why not upgrade to 0.9.0?
Post Reply

Who is online

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