Lua / Corona SDK Physics.addBody () - PullRequest
       11

Lua / Corona SDK Physics.addBody ()

0 голосов
/ 21 января 2019

Когда мой мяч поражает, но 30 мишеней 30 новых возвратов, за исключением того, что у меня есть сообщение об ошибке lua: 76: Physics.addBody () не может быть вызвано, когда мир заблокирован и в середине хруста числа, например, во время события столкновения почему?

function CreeNiveau()
    print("Crée  le Niveau 1 ")

    local lig,col ,x,y
    local largeurColonne = (display.actualContentWidth/(5+1))

    x = display.screenOriginX + largeurColonne
    y = display.screenOriginY + 100

    -- si une cible et toucher la Remove et donne des point

    local function onToucheCible(self, event)
    if event.phase == "began" then
        audio.play(sonBump)
        self:removeSelf()
        AjouteScore(25)
        nbCible = nbCible - 1
        print("Nombre de cible restent", nbCible)
        if nbCible == 0 then
            Recible()
        end
    end
end


for lig = 1,6 do  
    for col = 1, 5 do

        local cible = display.newCircle(x,y, 8)
        -- couleur des cible
        cible:setFillColor(1,math.random(),math.random())
        physics.addBody( cible, "static", { density = 1, friction = 0.3, bounce = 0.6, radius = 8})
        cible.collision = onToucheCible
        cible:addEventListener("collision")
        globaleview:insert(cible)
        x = x + largeurColonne
    end 

    y = y + 50
    x = display.screenOriginX + largeurColonne
end

1 Ответ

0 голосов
/ 23 января 2019

Вы, вероятно, используете физические функции / API в слушателе столкновений.Используйте timer.performWithDelay, чтобы отложить выполнение функции Recible:

local function onToucheCible( self, event )

    if event.phase == "began" then

        audio.play( sonBump )
        self:removeSelf()
        AjouteScore( 25 )
        nbCible = nbCible - 1
        print("Nombre de cible restent", nbCible)

        if nbCible == 0 then

            timer.performWithDelay( 50, Recible )

        end

    end

end

Подробнее:

...