munimisu
munimisu

Reputation: 35

Display/load a series of image using for loop

I have a set of images that I want to add to my scrollview using a for loop. My image set is named as Route01.png , Route02.png ... in this sequence. How can I code my for loop so I can load those images in sequence. My question is mostly on how can I code line 2 display.newImage(), I know I'm not doing it right. Thanks a lot in advance.

for i=1, 50 do
  image[i] = display.newImage("images/route/Route[i].png")
  image[i].x = display.contentCenterX
  image[i].y = spacing
  scrollView:insert(image[i])
end

Upvotes: 0

Views: 704

Answers (1)

munimisu
munimisu

Reputation: 35

I have found solution. I have changed line 2 to below and now all my images load to scrollview.

for i=1, 58 do
  image[i] = display.newImageRect( "images/route/Route" .. i .. ".jpg", 200, 60 )
  image[i].x = 90
  image[i].y = spacing
  scrollView:insert(image[i])
end

Upvotes: 1

Related Questions