Thanks guys.
If you’re interested, here’s how I ended up doing the random object spawning. There’s probably better (and less verbose) ways to do this, but this worked for me. I’m actually almost done with the game 
-- Nonmatching png table local imgs = { "images/ball.png", "images/camera.png", "images/dice.png", "images/fan.png", "images/goose.png", "images/hat.png", "images/marble.png", "images/orange.png", "images/pear.png", "images/radish.png", "images/strawberry.png" } nonMatchImageContainer = {} -- initialize nonmatching array local numOfImages = math.random(6,12) --spawn between 6 and 12 random objects on screen for i=1,numOfImages do -- loop to go from 1 to total number of images nonMatchImageContainer[i] = display.newImage(imgs[i]) -- create a new Rect for each item in loop -- randomize item's location on screen but keep within screen's boundaries nonMatchImageContainer[i].x = math.random(50, display.contentWidth - 50) nonMatchImageContainer[i].y = math.random(50, display.contentHeight - 50) nonMatchImageContainer[i]:addEventListener("tap", buttonListener2) -- make each item a button nonMatchImageContainer[i]:scale(.5,.5) nonMatchImageContainer[i]:rotate(math.random(-270,270)) --give each object a random initial rotation physics.addBody(nonMatchImageContainer[i], "dynamic", {radius = 55, density = 1.0, friction = 50, bounce = 100, isSensor = false}) nonMatchImageContainer[i].name = "nonmatchingitem" nonMatchImageContainer[i].postCollision = onOverlap nonMatchImageContainer[i]:addEventListener("postCollision", nonMatchImageContainer[i]) group:insert(nonMatchImageContainer[i]) end
onOverlap is just a method I call to prevent the objects from displaying on top of each other.
local onOverlap = function(self, event) if event.force \> 1 and not self.isHit then if event.other.myName == "nonmatchingitem" then --reposition item elsewhere nonMatchImageHolder[i].x = math.random(85, display.contentWidth - 85) nonMatchImageHolder[i].y = math.random(75, display.contentHeight - 180) print("Moved overlapping object") end end end