0

画面上を自動的に移動するランダムに生成されたオブジェクトがあります。オブジェクトが特定の x 位置に到達すると、それ自体がデスポーンするようにしたいのです。

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

local function spawncarright()
local rightcar = {408,312}

   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 = rightcar[math.random(1,2)]
   object[objectTag].name = objectTag
transition.to(object[objectTag], {time = 3500, x = 348})

end
timer.performWithDelay(2000,spawncarright,0)

object[objectTag].x = 348オブジェクトのデスポーンに到達すると

4

2 に答える 2

3

これを試して:

local function deSpawn()
  for i=1,objectTag do
    if(object[i]~=nil and object[i].x~=nil and object[i].x>=348)then
      -- If you want to remove the object, then use the following 2 lines --
      object[i]:removeSelf()
      print("Removed object["..i.."]")
      --or else if you want to reposition the object, then uncomment the following --
      --[[ 
        spawncarright()
      --]]
    end
  end
end
Runtime:addEventListener("enterFrame",deSpawn)

コーディングを続けてください........ :)

于 2013-10-18T15:44:22.247 に答える