A Newbie question from a Newb for you all!
I’m making some progress in my first corona app experience, yay.
I have created a table that stores my image file names.
I have randomly sorted the table, and
I have displayed 3 images from said table onto the screen!
I even have a home screen with a start button that takes you to a new scene before the previously mentioned stuff happens.
Question!
I want to track touches on the three images that are displayed.
I have seen many examples where an eventlistener is added to an on screen item like this…
-- displays the start button
local startBtn = display.newImage("start.png")
startBtn.x, startBtn.y = 160, 270
localGroup:insert( startBtn )
local function start ()
-- change the scene by going to game.lua
director:changeScene("game")
end
-- Start button listen for a tap event, and calls the 'start' function
startBtn:addEventListener("tap", start)
But how would I use the same principle when my images all have the same variable name because I have displayed them inside of a loop by picking them from the table?
for i=1, 3 do
local imgThing = display.newImage( imageList[i] )
imgThing.x = 70
imgThing.y = i\*60+200
localGroup:insert( imgThing )
end
Perhaps I should just assign them all eventlisteners based on their place in the table?
like
imgThing[1]:addEventListener(“tap”, start)
imgThing[2]:addEventListener(“tap”, start)
imgThing[3]:addEventListener(“tap”, start)
?
Or could I do that WITHIN the for loop like
imgThing[i]:addEventListener(“tap”, start)
?
Anyway, I better stop now before I get way off course.
Thanks for any suggestions! [import]uid: 191855 topic_id: 33643 reply_id: 333643[/import]