1
저는 코로나 SDK를위한 간단한 볼 타입 게임을 연구하고 있습니다. 현재는 화면상의 볼을 터치 할 때마다 게임 점수가 1 씩 증가하기를 원합니다. 현재 상황이 발생할 때마다 점수에 대한 텍스트 변수가 사라지고 아무 것도 발생하지 않습니다. 점수를 올리려면 어떻게합니까?터치시 스코어 인상 점수를 얻는 방법은?
function touchBall(event)
local ball = event.target
local score = 0;
scoreNum.text = score
scoreNum:setReferencePoint(display.CenterLeftReferencePoint);
score = score + 1
ball_h = 5
ball:applyLinearImpulse(0, -0.2, event.x, event.y)
ball_h = ball.y
if ball_h > 50 then
gameover();
end
if event.target == "touch" then
score = score + 1
scoreNum.text = score
end
end
ball:addEventListener("touch", touchBall)
ball2:addEventListener("touch", touchBall)
ball3:addEventListener("touch", touchBall)
end
코드 행 3에 "local score = 0;"이 표시됩니다. 지역 변수는 "score"변수는이 함수에만 사용되지만 함수 "touchBall (event)"는 여러 번 호출됩니다.이 함수를 호출하면 변수 "score"가 0으로 설정되므로 "local score = 0; " 함수 "touchBall (event)"에서 벗어났습니다. – Albert
실제로 작동했습니다. 감사합니다! –