I’ve been trying to swapp images for 6 hours following this tutorial: https://coronalabs.com/blog/2013/11/26/tutorial-techniques-for-swapping-images/
I can successfully put all my images in the group following this code:
local ballGroup = display.newGroup() local balls = {} local ballImages = { "images/red-ball.png", "images/blue-ball.png", "images/green-ball.png", "images/yellow-ball.png", "images/pink-ball.png" } for i = 1, #ballImages do balls[i] = display.newImageRect( ballGroup, ballImages[i], 128, 128 ) balls[i].x = display.contentCenterX balls[i].y = display.contentCenterY balls[i].isVisible = false end ballGroup.currentBall = 1 balls[ballGroup.currentBall].isVisible = true
But I can not make them change using this code in my widget button function event
local idx = t.currentBall balls[idx].isVisible = false idx = idx + 1 if ( idx \> #balls ) then idx = 1 end balls[idx].isVisible = true t.currentBall = idx
I know t = event.target, Is written above in the “handleTouch” function event.
I moved my touch event into the create scene because I was having a lot of local and global variable errors.
Now I’m stuck in the balls[idx].
I know it’s a scope problem.
I only have 12 different color images that I would like to be able to change them when I touch 12 different widget buttons. Each widget button would have a different color assigned.
Thanks in advance!