Hi!
I’ve been sitting on this one for 2 months now and I’m slowly losing interest in finishing my game, which is stupid since it’s 90% finished. So, I gathered the remaining motivation I had left and wrote this post here.
I’m having problems making my spawning objects not spawning at the same time. Right now there’s 4 objects spawning and then moving towards the character but when starting the game and later on when they spawn again they usually spawn in clusters and on top of eachother which just looks wrong. I’ve tried with alot of if’s but it didn’t work so I’m turning to you guys, any ideas and help would be greaaaatly appreciated!
Here’s the code for the objects(some comments are wrong, ignore those):
[code]
– CREATE OBSTACLES –
----------------------TRASH
local trash = display.newImage(“trash.png”)
trash.x = display.contentWidth + 30
trash.y = 245
trash:setReferencePoint(display.CenterReferencePoint);
frontfrontGroup:insert(trash)
----------------------MAILBOX
local mailbox = display.newImage(“mailbox.png”)
mailbox.x = display.contentWidth + 30
mailbox.y = 245
mailbox:setReferencePoint(display.CenterReferencePoint);
frontfrontGroup:insert(mailbox)
----------------------HOBO
local hobosheet = sprite.newSpriteSheet( “hobo.png”, 64, 55 )
local hoboset = sprite.newSpriteSet(hobosheet, 1, 5)
sprite.add( hoboset, “hobosleep”, 1, 4, 800, 0 ) – play 3 frames every 80 ms
sprite.add( hoboset, “hobowake”, 5, 1, 800, 1 ) – play 3 frames every 80 ms
local hobo = sprite.newSprite( hoboset )
hobo.x = display.contentWidth + 50
hobo.y = 236
hobo:setReferencePoint(display.CenterReferencePoint);
frontfrontGroup:insert(hobo)
hobo:prepare(“hobosleep”)
hobo:play(“hobosleep”)
----------------------DUMPSTER
local dumpster = display.newImage(“dumpster.png”)
dumpster.x = display.contentWidth + 30
dumpster.y = 255
dumpster:setReferencePoint(display.CenterReferencePoint);
frontfrontGroup:insert(dumpster)
----------------------STREETCAR
local streetcar = display.newImage(“streetcar.png”)
streetcar.x = display.contentWidth + 70
streetcar.y = 265
frontfrontGroup:insert(streetcar)
local obsCount = 1
local lampCount = 1
local isTrashSpawned = false
local isStreetCarSpawned = false
local isDumpsterSpawned = false
local isMailboxSpawned = false
local isHoboSpawned = false
local function spawnTrashDelay()
print(“spawning trash after delay”)
tm:add(trash, { time=12000, 0, x=trash.contentWidth - 30, onComplete = function() trash.x = display.contentWidth + 20 print(“trash DISPOSED!”) isStreetCarSpawned = false end} )
end
local function spawnStreetcar()
if isStreetCarSpawned == false then
local obsCount = math.random(1,500)
if obsCount == 1 then
print(“SPAWNING streetcar”)
isStreetCarSpawned = true
–print("isStreetCarSpawned(BEFORE CAR): ", isStreetCarSpawned)
tm:add(streetcar, { time=15200, 0, x=streetcar.contentWidth - 200, onComplete = function() streetcar.x = display.contentWidth + 70 print(“streetcar DISPOSED!”) print("isStreetCarSpawned(AFTER CAR): ", isStreetCarSpawned) end} )
end
end
end
local function spawnTrash()
if isTrashSpawned == false then
local obsCount = math.random(1,300)
if obsCount == 2 then
print(“SPAWNING trash”)
isTrashSpawned = true
–print("isTrashSpawned(BEFORE TRASH): ", isTrashSpawned)
tm:add(trash, { time=12000, 0, x=trash.contentWidth - 30, onComplete = function() trash.x = display.contentWidth + 30 print(“trash DISPOSED!”) isTrashSpawned = false print("isTrashSpawned(AFTER TRASH): ", isTrashSpawned) end} )
–else
–isTrashSpawned = true
–timer.performWithDelay(2000, spawnTrashDelay(), 1)
end
end
end
local function spawnDumpsterDelay()
print(“spawning dumpster after delay”)
tm:add(dumpster, { time=13000, 0, x=dumpster.contentWidth - 100, onComplete = function() dumpster.x = display.contentWidth + 30 print(“dumpster DISPOSED!”) isDumpsterSpawned = false end} )
end
local function spawnDumpster()
if isDumpsterSpawned == false then
local obsCount = math.random(1,300)
if obsCount == 3 then
isDumpsterSpawned = true
print(“SPAWNING dumpster”)
tm:add(dumpster, { time=13000, 0, x=dumpster.contentWidth - 100, onComplete = function() dumpster.x = display.contentWidth + 30 print(“dumpster DISPOSED!”) isDumpsterSpawned = false end} )
end
end
end
local function spawnMailboxDelay()
print(“spawning mailbox after delay”)
tm:add(mailbox, { time=14000, 0, x=mailbox.contentWidth - 125, onComplete = function() mailbox.x = display.contentWidth + 20 print(“mailbox gone!”) isMailboxSpawned = false end} )
end
local function spawnMailbox()
if isMailboxSpawned == false then
local obsCount = math.random(1,300)
if obsCount == 4 then
print(“SPAWNING mailbox”)
isMailboxSpawned = true
tm:add(mailbox, { time=14000, 0, x=mailbox.contentWidth - 125, onComplete = function() mailbox.x = display.contentWidth + 20 print(“mailbox gone!”) isMailboxSpawned = false end} )
end
end
end
local function spawnHobo()
if isHoboSpawned == false then
local obsCount = math.random(1,5)
if obsCount == 5 then
print(“SPAWNING hobo”)
isHoboSpawned = true
–print("isHoboSpawned(BEFORE CAR): ", isHoboSpawned)
tm:add(hobo, { time=16000, 0, x=hobo.contentWidth - 200, onComplete = function() hobo.x = display.contentWidth + 70 print(“hobo DISPOSED!”) isHoboSpawned = false end} )
end
end
end
[/code] [import]uid: 21652 topic_id: 19702 reply_id: 319702[/import]