Hello all.
In the game I’m working on, I have a table (array) of random images that appear in random different places on screen. My problem is that some images appear twice, and also some images are overlapping each other. Can you please point me in the right direction?
Here is my code:
-- Nonmatching Image Array local imgs = { "1\_bamboo.png", "2\_bow.png", "3\_bread.png", "4\_broccoli.png", "5\_brush.png", "6\_carrot.png", "7\_cheese.png", "8\_corn.png", "9\_diamond.png", "10\_eggs.png" }; --Populate screen with a group of nonmatching items local nonmatchgroup = display.newGroup(nonMatchImageHolder) nonmatchgroup:addEventListener( "touch", buttonListener ) nonmatchgroup:rotate(math.random(1,359)) nonMatchImageHolder = {} -- initialize array local numOfImages = math.random(1,5) -- define how many images on screen for i=1,numOfImages do -- start for loop to go from 1 to 10 local temp = math.random(1,12) nonMatchImageHolder[i] = display.newImageRect(imgs[temp], 250, 250) nonMatchImageHolder[i].x = math.random(75, display.contentWidth - 50) nonMatchImageHolder[i].y = math.random(75, display.contentHeight - 180) end group:insert(nonmatchgroup)
As always, any help is appreciated. Thanks!