나는 스마트 폰을위한 단순한 비디오 게임을 만들려고 했었습니다. 음, 이제 제가하려고하는 것은 'volMusicTickOn'객체를 클릭하면 사라져야하고 음악이 멈춰야한다는 것입니다. 나는 또한 사용하려고했습니다 내가 글로벌 'volMusicTickOn'(nil 값)을 인덱싱하려고 시도합니다. 리스너 오류
16:49:45.126 ERROR: Runtime error
16:49:45.126 C:\Users\lpasi\Downloads\Progetto 1-20170725T134427Z-001\Progetto 1\settings.lua:167: attempt to index global 'volMusicTickOn' (a nil value)
16:49:45.126 stack traceback:
16:49:45.126 [C]: in function 'error'
16:49:45.126 ?: in function 'gotoScene'
16:49:45.126 C:\Users\lpasi\Downloads\Progetto 1-20170725T134427Z-001\Progetto 1\menu.lua:36: in function '_onRelease'
16:49:45.126 ?: in function '?'
16:49:45.126 ?: in function <?:654>
16:49:45.126 ?: in function <?:169>
있어 오류 여기
local settings = composer.newScene()
local particlesTable = {}
local particlesGroup = display.newGroup()
local options =
{
width = 600,
height = 600,
numFrames = 2,
sheetContentWidth = 1200,
heetContentHeight = 600
}
local tickSheet = graphics.newImageSheet("rectTick_sheet.png", options)
--
--
function settings:create(event)
-- Dichiarazione oggeti e codice eseguibile
num=0
local sceneGroup = self.view
background = display.newImageRect(sceneGroup, "background.png", 1280 , 720)
background.x = display.contentCenterX
background.y = display.contentCenterY
volMusicTickOn = display.newImageRect( "rectTick_on.png", 100, 100)
volMusicTickOn.name = "volMusicTickOn"
volMusicTickOn.x = display.contentCenterX - 250
volMusicTickOn.y = display.contentCenterY - 100
end
function settings:show(event)
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
-- Code here runs when the scene is still off screen (but is about to come on screen)
elseif (phase == "did") then
if event.phase=="began"then
end
if event.phase=="ended"then
end
end
end
function settings:hide(event)
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
-- Code here runs when the scene is still off screen (but is about to come on screen)
elseif (phase == "did") then
-- Code here runs when the scene is entirely on screen
end
end
function settings:destroy(event)
local sceneGroup = self.view
end
-- Funzioni
local function remove(particle)
display.remove(particle)
table.remove(particlesTable, num)
end
local function removeParticle(particle)
timer.performWithDelay(1000, transition.to(particle, {alpha=0, time=350, onComplete=remove(particle) }))
end
local function removetotally(particle)
display.remove(particle)
table.remove(particlesTable, num)
end
function dimParticle(particle)
transition.to(particle, {alpha=0, time=500, onComplete = removetotally, onCompleteParams = particle})
end
local function generateParticles()
local xy=math.random(30,70)
local newParticle = display.newImageRect(particlesGroup, objectSheet , chooseColor(math.random(3)), xy, xy)
table.insert(particlesTable, newParticle)
num = num+1
newParticle.x = (math.random(1280)*math.random(88932))%1280
newParticle.y = (math.random(720)*math.random(13546))%720
newParticle.alpha = 0
transition.to(newParticle, {alpha=1, time=150, onComplete=dimParticle, onCompleteParams=newParticle})
end
local function generateParticlesSmall()
local xy=math.random(5,15)
local newParticle = display.newImageRect(particlesGroup, objectSheet , 1, xy, xy)
table.insert(particlesTable, newParticle)
num = num+1
newParticle.x = (math.random(1280)*math.random(88932))%1280
newParticle.y = (math.random(720)*math.random(13546))%720
newParticle.alpha = 0
transition.to(newParticle, {alpha=1, time=150, onComplete=dimParticle, onCompleteParams=newParticle})
end
local function chooseColor(n)
if n==1 then
return 8
elseif n==2 then
return 9
elseif n==3 then
return 10
end
end
function changeMusicVolumeStatus(event)
if audio.isChannelPaused(1) then
audio.resume(1)
else
audio.pause(1)
end
return true
end
local function changeEffectsVolumeStatus(event)
if audio.isChannelPaused(2) then
audio.resume(2)
else
audio.pause(2)
end
return true
end
-- Chiamate e Listener Del Runtime
bigPTimer1=timer.performWithDelay(1, generateParticles, 0)
bigPTimer2=timer.performWithDelay(1, generateParticles, 0)
smallPTimer=timer.performWithDelay(1, generateParticlesSmall, 0)
settings:addEventListener("create", settings)
settings:addEventListener("show", settings)
settings:addEventListener("hide", settings)
settings:addEventListener("destroy", settings)
volMusicTickOn:addEventListener("tap", changeMusicVolumeStatus)
volMusicTickOff:addEventListener("tap", changeMusicVolumeStatus)
--
return settings
한다 : 나는 함수 리스너를 통해 이런 짓을했지만 난 리스너를 호출에 오류가있어, 여기에 코드입니다 테이블 청취자하지만 아무것도 바뀌지 않았어, 내 문제를 해결하는 경우, 감사합니다.
volMusicTickOn이 nil 인 것 같습니다. 경로가 "rectTick_on.png"인지 확인하십시오. 올바른지, 파일 이름도 정확합니까? –
@Abadziluk 예, 그게 문제가 아니에요, 청취자의 의견을 말하려고했는데 그것은 정상적으로 화면에 나타납니다. –