2013-04-11 4 views
0

기본적으로 개체가 임의의 위치에서 화면을 벗어나서 화면을 벗어나 흐릅니다. 화면이 흐르면서 다시 화면에서 임의의 위치로 다시 설정되지만 플레이어가 충돌하는 경우에는 그럴 수 없습니다.충돌 후 다시 스폰합니다.

요약하면 플레이어와 충돌 할 때 오브젝트 위치 재 창작을 다시 스크린에서 없앨 수 있습니까?

개체 코드를 가공합니다. 여기


function moveUFO(self,event) 
    if self.x < -50 then 
    self.x = math.random(500,1500) 
    self.y = math.random(90,220) 
    self.speed = math.random(2,6) 
    self.amp = math.random(20,100) 
    self.angle = math.random(1,360) 
else 
    self.x = self.x - self.speed 
    self.angle = self.angle + .1 
    self.y = self.amp*math.sin(self.angle)+self.initY 
end 

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") 
는 충돌 감지

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) 

선박에 대한 코드입니다 :하여 addEventListener ("충돌", onCollision, 선박, addTime)

답변

0

내가하지 않았다면 충돌 감지에 대해 잘 모르는 오해. 이 페이지를 공부해야 : http://developer.coronalabs.com/content/game-edition-collision-detection

편집 부분 :

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) 

이 당신은 거기에 임의의 값을 수정할 수 있습니다 .. 그것을 할 것입니다. Corona 물리학은 충돌 시간에 모든 물리학 객체를 잠그기 때문에 충돌 시간에 객체를 바로 이동할 수 없습니다. 따라서 충돌 직후에 물체를 움직여야합니다.

+0

회신과 링크에 감사드립니다. 나는 대부분의 충돌 탐지를 이해하고 작동하는 몇 가지 설정이 있지만 충돌시 파괴 만합니다. 다시 화면 밖으로 시체를 다시 설정하려고 고심하고있는 Im. 떠 다니는 수집 가능한 별처럼. 어떻게 다시 포지션을 재설정 할 수 있을지 생각해? –

+0

충돌을 감지하는 코드 블록을 포함하여 질문을 편집하는 경우 easly help –

+0

도와 주셔서 감사합니다. 요청한대로 질문을 편집하셨습니다. 희망이 도움이됩니다. –

관련 문제