Events 不与电晕发生碰撞

Events 不与电晕发生碰撞,events,lua,collision-detection,coronasdk,collision,Events,Lua,Collision Detection,Coronasdk,Collision,我有一个新问题。。我修不好 我像一个球一样创造,当我点击时,球会移动到我点击的地方。所以这没关系。 我用框架填充了一些飞机,它们会随着重力下降 但我有一个问题,因为当球和飞机接触时,我的碰撞没有发生 有人能帮我吗?这是我的密码 -------------------------------------------------------- -- CHARACTER PART -- ----------------------

我有一个新问题。。我修不好

我像一个球一样创造,当我点击时,球会移动到我点击的地方。所以这没关系。 我用框架填充了一些飞机,它们会随着重力下降

但我有一个问题,因为当球和飞机接触时,我的碰撞没有发生

有人能帮我吗?这是我的密码

            --------------------------------------------------------
            -- CHARACTER PART --
            --------------------------------------------------------

            -- Creating the character --
            local _H = display.contentHeight;
            local _W = display.contentWidth;
            local character = display.newImageRect("images/small-black.png",80,80);
            character:setReferencePoint(display.CenterReferencePoint);
            character.x = _W/2; character.y = _H/2;
            character.color = "reddish";

            -- This is necessary so we know who hit who when taking care of a collision event
            character.name = "character"

            -- Listen to collisions
            character.collision = onCollision
            character:addEventListener("collision", character)

            -- Text to know the phase--
            local txt = display.newText("click state",0, 0, native.systemFont, 16*2);
            txt.xScale = 0.5; txt.yScale = 0.5;
            txt:setReferencePoint(display.CenterReferencePoint);
            txt.x = _W/2; txt.y = _H/2;

            -- Function on touch --
            function character:touch(e)
                if(e.phase == "began") then
                    txt.text = "Began Phase";
                    display.getCurrentStage():setFocus(e.target, e.id);
                elseif(e.phase =="moved") then
                    txt.text = "Moved phase";
                elseif(e.phase == "ended") then
                    txt.text = "Ended phase";
                    transition.to(self, {x = e.x, y = e.y, time=800});
                    transition.to(self, {x = e.x, y = e.y, time=800});
                end
            end

            -- Add event --
            character:addEventListener("touch", character);

            --------------------------------------------------------
            -- ENNEMY PART --
            --------------------------------------------------------

            -- Load and start physics
            local physics = require("physics")
            physics.start()

            -- Gravity --
            physics.setGravity(0, 20)


            -- Layers (Groups) --
            local gameLayer    = display.newGroup()
            local enemiesLayer = display.newGroup()

            -- Declare variables
            local gameIsActive = true
            local halfPlayerWidth
            local textureCache = {}
            textureCache[1] = display.newImage("images/enemy.png"); textureCache[1].isVisible = false;
            local halfEnemyWidth = textureCache[1].contentWidth * .5

            gameLayer:insert(enemiesLayer)


            -- Take care of collisions
            local function onCollision(self, event)

                -- Player collision - GAME OVER 
                if self.name == "character" and event.other.name == "enemy" and gameIsActive then

                    local gameoverText = display.newText("Game Over!", 0, 0, "HelveticaNeue", 35)
                    gameoverText:setTextColor(255, 255, 255)
                    gameoverText.x = display.contentCenterX
                    gameoverText.y = display.contentCenterY
                    gameLayer:insert(gameoverText)

                    -- This will stop the gameLoop
                    gameIsActive = false
                end
            end

            -- Add to main layer
            gameLayer:insert(character)


            -- Store half width, used on the game loop
            halfPlayerWidth = character.contentWidth * .5

            -- GAME LOOP --

            local  timeLastEnemy = 0, 0
            local function gameLoop(event)
                if gameIsActive then
                    -- Remove collided enemy planes
                    --for i = 1, #toRemove do
                        --toRemove[i].parent:remove(toRemove[i])
                        --toRemove[i] = nil
                    --end

                    -- Check if it's time to spawn another enemy,
                    -- based on a random range and last spawn (timeLastEnemy)
                    if event.time - timeLastEnemy >= math.random(600, 1000) then
                        -- Randomly position it on the top of the screen
                        local enemy = display.newImage("images/enemy.png")
                        enemy.x = math.random(halfEnemyWidth, display.contentWidth - halfEnemyWidth)
                        enemy.y = -enemy.contentHeight

                        -- This has to be dynamic, making it react to gravity, so it will
                        -- fall to the bottom of the screen.
                        physics.addBody(enemy, "dynamic", {bounce = 0})
                        enemy.name = "enemy"

                        enemiesLayer:insert(enemy)
                        timeLastEnemy = event.time
                    end

                end
            end

            -- Call the gameLoop function EVERY frame,
            -- e.g. gameLoop() will be called 30 times per second ir our case.
            Runtime:addEventListener("enterFrame", gameLoop)
问题解决了

别忘了写physics.addBody(…)