首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Lua / corona physics.addBody()

Lua / corona physics.addBody()
EN

Stack Overflow用户
提问于 2019-01-21 16:01:38
回答 1查看 246关注 0票数 1

当我的球命中了30个目标时,除了我有一个错误消息lua:76: physics.addBody()无法在世界被锁定并在数字处理过程中被调用之外,还有30个新的返回,比如在碰撞事件中为什么?

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-23 12:23:46

您可能在冲突侦听器中使用物理函数/API。使用timer.performWithDelay延迟Recible函数的执行:

代码语言:javascript
复制
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

阅读更多信息:

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54293622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档