Display multiple images as separate objects

How would I display multiple images as separate objects that can be manipulated individually.
I thought I should be able to define an array of images as objects, give them properties and then display and manipulate them based on their array key.

local page = {“Page01s.jpg”, “Page02s.jpg”, “Page03s.jpg”, “Page04s.jpg”, “Page05s.jpg”, “Page06s.jpg”, “Page07s.jpg”}

pageCount = 7
for i=1,pageCount do
local image[i] = display.newImage(page[i])
image[i].rotation = 90
end

display.image[1]
transition.to( image[1], { xScale=0, time=1500 } ) [import]uid: 6397 topic_id: 1044 reply_id: 301044[/import]

There are some issues with your code. I recomment running this code with the corona terminal and you will see where the errors pop up.

So what are these issues:

  1. As you have defined image as a local inside the FOR loop, the transition.to command does not know this image definition. Please study the scoping rules in LUA.
  2. You don’t position your images differently, the last one is the top most image you see. They get drawn automatically.
  3. display.image is not a valid command.
  4. As is no.1, the image[1] in the transition command is NIL, so it will throw an error. And if you defined the image outside the for loop, you still would not see your transition as is would be covered by the over 6 images.

Here is a sample which should work. I didn’t test it, but I think it is ok:
[lua]local page = {“Page01s.jpg”, “Page02s.jpg”, “Page03s.jpg”, “Page04s.jpg”, “Page05s.jpg”, “Page06s.jpg”, “Page07s.jpg”}
local image
for i=1,#page do
image[i] = display.newImage(page[i])
image[i].rotation = 90
image[i].x = i*15
image[i].y = i*30
end
transition.to( image[1], { xScale=0, time=1500 } )[/lua]
[import]uid: 5712 topic_id: 1044 reply_id: 2567[/import]

Thanks for the quick reply Mike. I tried your code and it displays image[1] but the code seems to stop at line 5.
I really appreciate the help on this. I’ve been trying to get a handle on dealing with arrays of images for over a week now. [import]uid: 6397 topic_id: 1044 reply_id: 2570[/import]

Like I said, it should have worked :slight_smile:

Change the local image deifnition to this:

[lua]local image = {}[/lua] [import]uid: 5712 topic_id: 1044 reply_id: 2571[/import]

Awesome Mike!!! That works perfectly. I can’t thank you enough! [import]uid: 6397 topic_id: 1044 reply_id: 2574[/import]