2014-04-07 18 views
1

이 코드입니다 : 게임은 떨어지는 공을 생성내 센서를 corona sdk에서 제대로 작동하게 만드는 방법은 무엇입니까?

local bottombar = display.newLine(0, 480, 340, 480) 
physics.addBody(bottombar, "static", {isSensor = true}) 

function bottombar:collision(event) 
    if(event.phase == "began") then 
     a = a + 1 
     print(a) 

     if(a == 4) then 
      timer.cancel(timer1) 
      storyboard.gotoScene("scene_results") 
     end 
    end 
end 

bottombar:addEventListener("collision", bottombar) 

end 

와 나는 3 공 바닥 line.Variable 'A는 처음에 0, 첫 번째 공을 패스를 통해 통과 할 때 게임을 중지하려면 콘솔의 라인 A는 1 번째 공은 라인을 통해 전달 될 때 콘솔 A는 2이고 저를 도시이다 통해 이런 다음 라인 3 :

1 => first ball 
2 } 
    }=> second ball 
3 } 

I가 if(a == 10)을하면 첫 번째 공 'a'는 1, 두 번째 공 'a'는 (2, 3), 세 번째 'a'는 (4, 5, 6)이며 네 번째 공이 'a'선을 통과하면 (7 , 8, 9, 10).

또는 (내가 그들을 터치하면 self:removeSelf()) 내가 3 개 공을 파괴하고 난 4 볼이 라인을 통해 통과 할 경우 'A'가 될 : 난 문법 실수가있는 경우

1 
2 
3 
4 

가 미안 해요.

이 전체 코드가, 내가 잘못 뭘하는지 알아낼 수있다 :

local a = 0 
local score = 0 

local function game() 
    local pop = audio.loadSound("pop.WAV") 
    local masterVolume = audio.getVolume() 

    local function createCircle() 
     function onCircleTouch(self, event) 
      if(event.phase == "began") then 
       timer.performWithDelay(1, function() 
        self:removeSelf() 
        audio.play(pop,{channel=0,loops=0}) 
        score=score+10 
        globals.score = score 
       end) 
      end 
      return true 
     end 
     local circle = display.newImage("ballon2.png",math.random(10,300),0) 
     physics.addBody(circle, "dynamic", { desity=1.0,friction=0 }) 
     circle.touch = onCircleTouch 
     circle:addEventListener("touch", circle) 
    end  

    local function balls(event) 
     createCircle() 
     local bottombar=display.newLine(0, 480, 340, 480) 
     physics.addBody(bottombar, "static" ,{isSensor=true}) 
     function bottombar:collision(event) 
      if(event.phase == "began") then 
       a=a+1 
       print (a, event.other) 
       if(a == 3) then 
        timer.cancel(timer1) 
        storyboard.gotoScene("scene_results") 
       end 
      end 
     end 
     bottombar:addEventListener("collision", bottombar) 
    end 

    timer1=timer.performWithDelay(1000, balls, 0) 
end 

game() 
+0

어떻게 신고합니까? 지역 a = 0? –

+0

@TeddyEngel 예 –

+0

@Schollii이 코드는 무한한 공을 생성합니다 (timer1 = timer.performWithDelay (1000, balls, 0)) –

답변

0

마지막으로 내 문제에 대한 해결책을 찾았습니다. 나는 local score = 0이 아래에 넣어 :

local bottombar=display.newLine(0, 480, 340, 480) 
physics.addBody(bottombar, "static" ,{isSensor=true}) 

이 아래에 난 bottombar:addEventListener("collision", bottombar)을 넣어.

0

내가 문제를 재현 할 수없는 오전 : 난 당신이 게시 코드를했다, 3 개 버튼을 만든 나는 물리학에 동적 객체를 추가하고 그것을 라인쪽으로 떨어 뜨리게했습니다. 나는 몸마다 하나의 출력물을 얻는다. 코드의 다른 부분에서 뭔가가 일어나고 있습니다. 최소한의 독립 실행 형 예제를 만들 수 있습니까? 문제가 무엇인지 분명하게 알 수 있습니다.

어떤 것들은 확인 :

  1. 당신이 충돌 이벤트 동안 충돌 공을 제거하지 않는 것이 확인합니다. 추가 충돌이 물리 엔진이 여전히 스타일 라인

메모를 통과 한 공을 진화하고 있음을 나타내는 것이다, 다른 공을 포함하는지 print(a, event.other)에 제거를

  • 변경 인쇄를 지연해야합니다 : 루아 () 주위에 if 조건이 필요하지 않습니다. ()은 중복되어 노이즈가 추가됩니다.

  • +0

    @VoicuPetre SO는 토론 스레드가 아니므로, 코멘트를 넣지 마십시오. 코멘트는 주로 답변을 원하는 사람들을위한 것입니다. 따라서 질문에 누락 된 정보가 무엇인지 나타낼 수 있습니다. – Schollii

    +0

    나는 print (a)를 print (a, event.other)로 변경했다. 그 다음엔 1 공백을 그리고 나서 table : 01CDDA50.I는 무엇을 의미하는지 모르며 인터넷에서 아무것도 발견하지 못했다. –

    +0

    @VoicuPetre 훨씬 더 나은, 질문에 덧글을 추가했습니다, 당신이 문제를 재현하는 게시하지 생각하지 않습니다 – Schollii

    관련 문제