0

I want to spawn a image at y = 408 and y = 360. I have the random sprite code just don't know how to spawn it in two specific places on the screen.

local  mRandom = math.random
local  objects = {"Vehicle11" ,"Vehicle21","Vehicle31","Vehicle41"}
local objectTag = 1
local object = {}

local function spawncarright()
    objectTag = objectTag + 1
    local objIdx = mRandom(#objects)
    local objName = objects[objIdx]
    object[objectTag]  = display.newImage(objName..".png")  -- see the difference here
    object[objectTag].x = 32
    object[objectTag].y = 408
    object[objectTag].name = objectTag
    print(objectTag)
end
timer.performWithDelay(1000,spawncarright,0)
4

1 回答 1

3

Just a small modification should do the work

local  mRandom = math.random

local  objects = {"Vehicle11" ,"Vehicle21","Vehicle31","Vehicle41"}
local objectTag = 1
local object = {}

local function spawncarright(y)
    objectTag = objectTag + 1
    local objIdx = mRandom(#objects)
    local objName = objects[objIdx]
    object[objectTag]  = display.newImage(objName..".png")  -- see the difference here
    object[objectTag].x = 32
    object[objectTag].y = y
    object[objectTag].name = objectTag
end
timer.performWithDelay(1000, function() spawncarright(408); spawncarright(360);  end,0)
于 2013-10-18T16:53:25.423 回答