Lua 重新设置碰撞后的繁殖

Lua 重新设置碰撞后的繁殖,lua,coronasdk,collision,Lua,Coronasdk,Collision,基本上,发生的是对象在屏幕外的任意位置生成,然后流入和流出屏幕视图。 当他们在屏幕上移动时,他们会在屏幕外的一个随机位置重新设置,但是如果玩家与它发生碰撞,我就无法实现这一点 总而言之,在与玩家发生碰撞时,我如何使物体位置在屏幕外重新出现 这是目标代码 UFO = display.newImage("ufo.png") UFO.name = "UFO" UFO.x = 640 UFO.y = 100 UFO.speed = math.random(2,6) UFO.initY

基本上,发生的是对象在屏幕外的任意位置生成,然后流入和流出屏幕视图。 当他们在屏幕上移动时,他们会在屏幕外的一个随机位置重新设置,但是如果玩家与它发生碰撞,我就无法实现这一点

总而言之,在与玩家发生碰撞时,我如何使物体位置在屏幕外重新出现

这是目标代码

UFO = display.newImage("ufo.png")
  UFO.name = "UFO"
  UFO.x = 640
  UFO.y = 100
  UFO.speed = math.random(2,6)
  UFO.initY = UFO.y
  UFO.amp = math.random(20,100)
  UFO.angle = math.random(1,360)
  physics.addBody(UFO, "static")


ship:addEventListener(“碰撞”,onCollision,ship,addTime)

如果我没有误解您不知道碰撞检测。您应该学习此页面:

编辑部分:

function ship:collision(event)
    if (event.other.name == 'UFO') then
          timer.performWithDelay( 50, function() event.other.x = math.random( 0, 320 ); event.other.y = math.random( 0.480 ); end, 1 )
          scoreAnim = display.newText('+10', ship.x, ship.y-10, native.systemFontBold, 16)
          transition.to(scoreAnim, {time = 1000, y = scoreAnim.y - 30, alpha = 0, onComplete = function() display.remove(scoreAnim) scoreAnim = nil end})
          scoreAnim:setTextColor(0,255,12)
          --increases score
          collectedN.text = tostring(tonumber(collectedN.text) + 1)

这就行了。。你可以在那里修改随机值。你们不能在碰撞时间移动你们的物体,因为电晕物理,在碰撞时间锁定所有的物理物体。因此,应该在碰撞后立即移动对象

嘿,谢谢你的回复和链接。我确实了解大多数碰撞检测,并有一些工作的设置,但只是在碰撞时销毁。我只是在努力重新把它的身体从屏幕上移开,让它重新回到屏幕上。有点像一颗漂浮的收藏之星。你知道我如何重新设置它的位置吗?如果你编辑你的问题,包括你检测碰撞的代码块,我可以很容易地帮你。谢谢你的帮助,我按照你的要求编辑了我的问题。希望能有帮助。我不明白你们为什么移除不明飞行物命名的物体。你不想更新它的位置,而不是删除它吗?我上一次处理它时试图重新生成它,但从未工作过。我确实希望在碰撞后将其位置更新为随机的x和y。
    function ship:collision(event)
            if (event.other.name == 'UFO') then
                    event.other:removeSelf(self)
                    scoreAnim = display.newText('+10', ship.x, ship.y-10, native.systemFontBold, 16)
                    transition.to(scoreAnim, {time = 1000, y = scoreAnim.y - 30, alpha = 0, onComplete = function() display.remove(scoreAnim) scoreAnim = nil end})
                    scoreAnim:setTextColor(0,255,12)
                   --increases score
                    collectedN.text = tostring(tonumber(collectedN.text) + 1)
function ship:collision(event)
    if (event.other.name == 'UFO') then
          timer.performWithDelay( 50, function() event.other.x = math.random( 0, 320 ); event.other.y = math.random( 0.480 ); end, 1 )
          scoreAnim = display.newText('+10', ship.x, ship.y-10, native.systemFontBold, 16)
          transition.to(scoreAnim, {time = 1000, y = scoreAnim.y - 30, alpha = 0, onComplete = function() display.remove(scoreAnim) scoreAnim = nil end})
          scoreAnim:setTextColor(0,255,12)
          --increases score
          collectedN.text = tostring(tonumber(collectedN.text) + 1)