coronasdk/Lua:一个表';在碰撞事件期间通过event.other访问时,s属性为nil。但是为什么呢?

coronasdk/Lua:一个表';在碰撞事件期间通过event.other访问时,s属性为nil。但是为什么呢?,lua,null,coronasdk,collision,Lua,Null,Coronasdk,Collision,我有一个模块,它在游戏中的所有活动都在这个模块中。在t.physics中,我添加了一个碰撞事件侦听器(区分目标是组还是单个对象)。当相关对象检测到碰撞时,另一个对象(事件.other)的属性col)似乎是nil,尽管我最初在t.create中将其设置为表示颜色的字符串。我就是找不到原因,有人吗 谢谢你的帮助。 你好,尼尔斯 local fence = require("lib.fence") local physics = require("physics") local t = {}

我有一个模块,它在游戏中的所有活动都在这个模块中。在
t.physics
中,我添加了一个碰撞事件侦听器(区分目标是组还是单个对象)。当相关对象检测到碰撞时,另一个对象(
事件.other
)的属性
col
)似乎是
nil
,尽管我最初在
t.create
中将其设置为表示颜色的字符串。我就是找不到原因,有人吗

谢谢你的帮助。 你好,尼尔斯

local fence = require("lib.fence")
local physics = require("physics")
local t = {}
    local stages = {yellow = 1, lila = 1, red = 1}
    local sizes = {1, 3.625, 7.25}
    t.colors = {"yellow", "lila", "red"}
    t.growing = false

    t.setSize = function(fill)
        local tHeight = fill.contentHeight * sizes[stages[fill.col]]
        local tScale = tHeight / fill.contentHeight
        fill.yScale = tScale

    end

    t.grow = function(group, color, hero)
        local counter = 0
        stages[color] = stages[color] + 1
        for i = 1, group.numChildren, 1 do
            if group[i].col == color then
                counter = counter + 1
                local function newPhysics() t.physics(group) end
                if counter == 1 then
                    local function reset() t.growing = false if stages[color] == 3 then stages[color] = 1; newPhysics(); end end
                    local function start() t.growing = true end
                    transition.to(group[i], {time = 260, yScale = sizes[stages[color]], onStart = start, onComplete = reset})
                else
                    transition.to(group[i], {time = 250, yScale = sizes[stages[color]], onStart = start})
                end
            end
        end
    end

    t.physics = function(target)
        if target.numChildren == nil then
            physics.removeBody(target)
            local function add()
                physics.addBody( target, "static", {isSensor = true} )
                target.collision = function(self, event)
                    if event.phase == "began" then
                        target.count = target.count + 1
                        if target.count == 1 then
                            t.grow(target.parent, self.col, event.other)
                        end
                    elseif event.phase == "ended" then
                        target.count = 0
                    end
                end
            end
            timer.performWithDelay(1, add, 1)
        else
            for i = 1, target.numChildren, 1 do
                physics.removeBody( target[i] )
                physics.addBody( target[i], "static", {isSensor = true} )
                target[i].name = "fill"
                local fill = target[i]
                fill.count = 0
                fill.collision = function(self, event)
                    if event.phase == "began" then
                        self.count = self.count + 1
                        if self.count == 1 and event.other.x ~= nil then
                            t.grow(target, self.col, event.other)
                        end
                    else
                        fill.count = 0
                    end
                end
                fill:addEventListener("collision")
            end
        end
    end

    t.setColor = function(fill)
        local colors = {
            {238 / 255, 228 / 255, 28 / 255},
            {38 / 255, 33 / 255, 77 / 255},
            {175 / 255, 24 / 255, 52 / 255},
        }
        local names = {"yellow", "lila", "red"}
        local r = math.random(3)
        fill.fill = colors[r]
        fill.col = names[r]
    end

    t.create = function(fences, group, colors)
        local fills = {}
        for i = 1, #fences, 1 do
            local rCol = math.random(3)
            local col
            if rCol == 1 then
                col = colors.yellow
            elseif rCol == 2 then
                col = colors.lila
            else
                col = colors.red
            end
            fills[i] = display.newRect(
                group, fences[i].x + fences[i].contentWidth * 0.125, fences[i].y,
                fences[i].contentWidth * 0.9, (fences[i].contentHeight * 0.5 / 3)
            )
            fills[i].dPosX = fills[i].x
            fills[i].y = display.contentHeight- fills[i].contentHeight / 2
            fills[i].fill = col
            fills[i].col = t.colors[rCol]
            fills[i].increased = false
        end
        return fills
    end

    t.move = function(fills, fences, group)
        for i = 1, #fills, 1 do
            local fill = fills[i]
            function fill:enterFrame()
                self:translate(fence.speed, 0)
                if t.growing == false then
                    t.setSize(self)
                end
                if self.x > display.contentWidth + 0.55 * fences[i].contentWidth then
                    local xT = {}
                    for i = 1, group.numChildren, 1 do
                        xT[i] = group[i].x
                    end
                    local function compare(a, b) return a < b end
                    table.sort(xT, compare)
                    self.x = xT[1] - fences[i].contentWidth * 0.98
                    t.setColor(self)
                    local function newPhysics() t.physics(self) end
                    timer.performWithDelay( 25, newPhysics, 1 )
                    self:toBack()
                end
            end
            Runtime:addEventListener("enterFrame", fill)
        end
    end
return t
localfence=require(“lib.fence”)
本地物理=要求(“物理”)
局部t={}
本地阶段={yellow=1,lila=1,red=1}
本地大小={1,3.625,7.25}
t、 颜色={“黄色”、“利拉”、“红色”}
t、 增长=错误
t、 设置大小=功能(填充)
local tHeight=fill.contentHeight*大小[stages[fill.col]]
本地tScale=灯/填充物高度
fill.yScale=t刻度
结束
t、 成长=功能(组、颜色、英雄)
本地计数器=0
阶段[颜色]=阶段[颜色]+1
对于i=1,group.numChildren,1 do
如果组[i].col==颜色,则
计数器=计数器+1
局部函数newPhysics()t.physics(组)end
如果计数器==1,则
局部函数重置()t.growing=false,如果stages[color]=3,则stages[color]=1;新物理学();结束
本地函数start()t.growing=true结束
转换到(组[i],{time=260,yScale=size[stages[color]],onStart=start,onComplete=reset})
其他的
转换到(组[i],{time=250,yScale=size[stages[color]],onStart=start})
结束
结束
结束
结束
t、 物理=功能(目标)
如果target.numChildren==nil,则
物理。移除实体(目标)
局部函数add()
addBody(目标,“静态”,{isSensor=true})
target.collision=函数(自身、事件)
如果event.phase==“开始”,则
target.count=target.count+1
如果target.count==1,则
t、 增长(target.parent、self.col、event.other)
结束
elseif event.phase==“结束”然后
target.count=0
结束
结束
结束
timer.performWithDelay(1,add,1)
其他的
对于i=1,target.numChildren,1 do
物理移除体(目标[i])
addBody(target[i],“static”,{isSensor=true})
目标[i]。name=“填充”
局部填充=目标[i]
fill.count=0
fill.collision=函数(自身、事件)
如果event.phase==“开始”,则
self.count=self.count+1
如果self.count==1,event.other.x~=nil,则
t、 增长(目标、self.col、event.other)
结束
其他的
fill.count=0
结束
结束
填充:addEventListener(“碰撞”)
结束
结束
结束
t、 setColor=函数(填充)
本地颜色={
{238 / 255, 228 / 255, 28 / 255},
{38 / 255, 33 / 255, 77 / 255},
{175 / 255, 24 / 255, 52 / 255},
}
本地名称={“黄色”、“lila”、“红色”}
局部r=数学随机(3)
fill.fill=颜色[r]
fill.col=名称[r]
结束
t、 创建=功能(栅栏、组、颜色)
局部填充={}
对于i=1,#围栏,1 do
本地rCol=数学随机(3)
地方学院
如果rCol==1,则
col=颜色。黄色
elseif rCol==2,则
col=colors.lila
其他的
col=颜色。红色
结束
填充[i]=display.newRect(
组,fences[i].x+fences[i].contentWidth*0.125,fences[i].y,
围栏[i].contentWidth*0.9,(围栏[i].contentHeight*0.5/3)
)
填充[i].dPosX=填充[i].x
填充[i]。y=display.contentHeight-填充[i]。contentHeight/2
填充[i]。填充=列
填充[i].col=t.colors[rCol]
填充[i]。增加=错误
结束
返回填充
结束
t、 移动=功能(填充、围栏、组)
对于i=1,#填充,1 do
局部填充=填充[i]
函数填充:enterFrame()
self:translate(fence.speed,0)
如果t.growing==false,则
t、 设置大小(自身)
结束
如果self.x>display.contentWidth+0.55*fences[i].contentWidth,则
本地xT={}
对于i=1,group.numChildren,1 do
xT[i]=组[i].x
结束
本地函数比较(a,b)返回a
这里似乎没有任何动态实体。什么与什么碰撞?可能是碰撞中涉及的另一个对象(event.other的值
不是在
t.create()
中初始化的,因此没有
col
属性吗