This is probably a simple fix, but it’s driving me nuts and I can’t think of a logical solution to it. So, here it is:
I’m trying to create a random (1-3) group of items off screen and then have them scroll across the screen after they are created. This part is working fine. The problem I am having is that the items overlap from time to time and I’m not sure how to stop that from happening. Here is the code:
[lua]local createJunk2 = function()
local i=1
local Junk2 = {}
local JunkSet2 = m.random(1,3)
local JunkSet2x
for i=1,JunkSet2 do
JunkSet2x = m.random(961, 1919)
Junk2[i] = display.newImageRect(“images/junk.png”, 100, 22);
Junk2[i]:setReferencePoint(display.CenterReferencePoint);
Junk2[i].x = JunkSet2x; Junk2[i].y = _H - 60;
end
end[/lua]
I’m assuming that there is an easy way to do this with a loop that checks the x position of the previous junk images that were placed and generates a new random number if it is within 100 pixels left or right, but it’s just not coming to me. Any help would be appreciated.
Thanks Guys [import]uid: 125081 topic_id: 27119 reply_id: 327119[/import]