Displays correctly:
function spawn() numFlies = math.random(15,16) halfW = display.viewableContentWidth / 2 halfH = display.viewableContentHeight / 2 for i=1,numFlies do print("fly added") flying = display.newImage("flyingfly.png", 12, 12) splat = display.newImage("flysplat.png",12,12) flygroup = display.newGroup() flygroup:insert(flying, true) flygroup:insert(splat, true) splat.isVisible = false -- Add to spawned flies count per fly added. spawnedflies = spawnedflies + 1 print(spawnedflies) -- add physics to the fly, the filter is to assign them different bits so tehy don't collide. physics.addBody(flygroup, {bounce = 1, density = 1, filter = {maskBits = 2, categoryBits = 4}}) flygroup.gravityScale = 0 flygroup:translate( halfW + math.random( -100, 100 ), halfH + math.random( -100, 100 ) ) flygroup:addEventListener( "touch", buttonListener ) -- set velocity in pixels per second. velocityx = math.random(-100,200) velocityy = math.random(-100,200) flygroup:setLinearVelocity(velocityx,velocityy) -- If statement to detect which way the flies are moving and display the image accordingly. if velocityx \< 0 then flygroup:scale(-1,1) else flygroup:scale(1,1) end t = 1 end spawner() flylistener() end
