I don’t understand why my objects aren’t spawning… I followed everything that Beebe wrote in his code but I’m not grasping it… I replaced his movie clips with sprite loq…
[lua]display.setDefault(“background”, 255, 255, 255)
display.setStatusBar (display.HiddenStatusBar)
local physics = require( “physics” )
physics.start()
carSpawnRate = 3 --> how many seconds between each spawn
local gameGroup = display.newGroup()
local cGroup = display.newGroup()
gameGroup:insert( cGroup )
– EXTERNALS
local ui = require(“ui”)
local mRand = math.random
local mCeil = math.ceil
– LOGIC VARIABLES
local cCount
– GAME VARIABLES/SETTINGS
local carSpawnFrameCount = 1
local isOnFirstCar = true
local currentComeFrom = mRand( 1, 4 ) --> controls direction in which spawn from
local spawnNewCar = function( params )
local c, x, y, cameFrom
local loqsprite = require(‘loq_sprite’)
local cf = loqsprite.newFactory(‘sheet’)
local c = cf:newSpriteGroup()
local cRectShape = c:getRectShape()
cBody = { friction=0, bounce=0.1, density=0, shape = cRectShape }
physics.addBody(c, “dynamic”, cBody)
c.x = params.x; c.y = params.y
c:play(“greenCar drive”)
cCount = #cGroup
c.framePosition = 1
c.selfCount = cCount
c.frameCount = 1
c.cameFrom = params.cameFrom
local spawnNewCar = function()
– First decide what side of the screen object will come from
local theX, theY
currentComeFrom = currentComeFrom + 1
if currentComeFrom > 4 then
currentComeFrom = 1
end
local comeFrom = currentComeFrom
if comeFrom == 1 then --> left side of screen
if isOnFirstCar then
isOnFirstCar = false
theX = 0
else
theX = 0
end
theY = mRand( 50, 270 )
elseif comeFrom == 2 then --> top of screen
if isOnFirstCar then
isOnFirstCar = false
theY = 0
else
theY = 0
end
theX = mRand( 50, 430 )
elseif comeFrom == 3 then --> right side of screen
if isOnFirstCar then
isOnFirstCar = false
theX = 480
else
theX = 480
end
theY = mRand( 50, 270 )
elseif comeFrom == 4 then --> bottom of screen
if isOnFirstCar then
isOnFirstCar = false
theY = 320
else
theY = 320
end
theX = mRand( 50, 430 )
end
newCar( {
x = theX,
y = theY,
cameFrom = comeFrom
})
end
–===================================================================================
–
–===================================================================================
local carSpawner = function( event )
local spawnRate = mCeil(carSpawnRate * 60)
if carSpawnFrameCount >= spawnRate then
carSpawnFrameCount = 1 --> reset the counter
– Spawn a new Car
spawnNewCar()
else
carSpawnFrameCount = carSpawnFrameCount + 1
end
Runtime:addEventListener( “enterFrame”, carSpawner )
end
end
– MUST return a display.newGroup()
return gameGroup
end [/lua]
I just want to know why they aren’t showing up [import]uid: 51459 topic_id: 12299 reply_id: 312299[/import]