[Solved]List of simple sprite

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.
Post Reply
User avatar
var77
Citizen
Posts: 52
Joined: Wed May 02, 2018 1:57 pm

[Solved]List of simple sprite

Post by var77 »

Hi everyone i'm trying to do simple list of sprite
but i guess i'm missing something. I may handle list
badly or the for loop. Here is the code:

Code: Select all

-- INIT FUNCTIONS
button = {x=scr.w/2,y=scr.h/2,w=45,h=49,img=nil}
buttons = {}
function love.load()
	button.img = love.graphics.newImage('assets/buttonSquare_grey.png')
	button.img:setFilter("nearest", "nearest", 0)	
	buttons = {button.img,button.img,button.img}
end

function love.draw()
	for i = 1,table.getn(buttons) do
		love.graphics.draw(buttons[i], button.x*1.1, button.y)
	end	
end
What i clearly expect is only a list of three sprite (list=[a,b,c])
that are print next to each one (ex: (A)(B)(C)). So if anyone got an idea ?

Thanks in advance.
Last edited by var77 on Tue May 22, 2018 9:55 am, edited 1 time in total.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: List of simple sprite

Post by grump »

var77 wrote: Tue May 22, 2018 9:35 am What i clearly expect is only a list of three sprite (list=[a,b,c])
that are print next to each one (ex: (A)(B)(C)). So if anyone got an idea ?
You're drawing all buttons at the same position. And you store only the button image in buttons, not distinct button tables for each button.
User avatar
var77
Citizen
Posts: 52
Joined: Wed May 02, 2018 1:57 pm

Re: List of simple sprite

Post by var77 »

Thanks for your answer grump. My clearly miss was for sure the same position.

with that correct i can distinct each draw with the for loop:

Code: Select all

for i = 1,table.getn(buttons) do
	love.graphics.draw(buttons[i], button.x+i*button.w, button.y)
end
And you store only the button image in buttons, not distinct button tables for each button.
I may gonna add also list of list but it was just a test.
Thanks a lot :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 39 guests