There are many attempts
You could spawn those objects as physical objects with isSensor, give them a collision handler and when colliding, removing.
I don’t know if those objects would actually flash…
Another method would be to make random coordinates and then loop through every object and check if it’s at least some pixels away.
Here’s some pseudoCode:
[code]
llocal mySpawnedObjects = {}
local function distance(ax,ay,bx,by)
return (math.sqrt(math.pow(bx-ax,2)+math.pow(by-ay,2)))
end
local function spawnObject()
local rX = math.random(0,display.contentWidth)
local rY = math.random(0,display.contentHeight)
for i=0,#mySpawnedObjects,1 do
if (#mySpawnedObjects == 0) then
– First Object, spawn anywhere
local myObject = display.newRect(rX,rY,10,10)
table.insert(mySpawnedObjects,myObject)
else
– Min Distance - 100 pixels
– we need to do i+1 since lua tables start with the index of 1
local distance = math.round(distance(rX,rY,mySpawnedObjects[i+1].x,mySpawnedObjects[i+1].y))
print(distance)
if (distance >= 100) then
– create Object and place it into the array
local myObject = display.newRect(rX,rY,10,10)
table.insert(mySpawnedObjects,myObject)
else
print(“too close, can’t spawn”)
end
end
end
end
local spawnTimer = timer.performWithDelay(500,spawnObject,0)
[code]
Can’t test it right now, but will test it later. [import]uid: 13097 topic_id: 17860 reply_id: 68173[/import]