Corona SDK - 触摸透明度问题。物理事件 body?

Corona SDK - touch transparency issue. Event on physics body?

这里是新手! :P

我正在尝试在 Corona 中创建一个游戏,其中动物从屏幕顶部掉落并不断弹跳。当您触摸动物时,它会消失。

我把所有的动物都画成了圆圈,然后,我给它添加了一个圆形物理body。图像是透明的 PNG。

问题是,动物的一些细节,比如耳朵和爪子,它们不在物理范围内body(我想要的,因为这样碰撞似乎更好)。此外,当我触摸动物图像外部时,有时它会被压在我图像的 alpha 区域上,这被视为点击,但我实际上并没有点击动物。

我希望它在我仅单击其物理 body 区域时消失。

有人知道怎么处理吗?有没有办法为物理 body 添加触摸处理程序? (碰撞效果很好,只是与图像相关的触摸而不是物理body)。

local rect = display.newImage("img/Animals/cow_a1.png");
rect.x = 60 + math.random( 160 )
rect.y = -100
physics.addBody( rect, { density=9, friction=0.3, bounce=0.3,radius=27} )
function rect:touch(e)
            -- Remove the animals from screen and memory
            removeAnimal(self);
end
-- Add event listener to the cow
rect:addEventListener("touch", rect);

这是因为矩形图像space。尝试在您的动物对象上使用 MASK 并启用 HIT TEST 选项(真): try this link for masking images

这里有一个例子:

local displayGroupTmp = display.newGroup( )
    displayGroupTmp.id = id + 1
    -- creating a slice
    local circleSize = Constants.screenX*3.8/4 - 20
    local background = display.newImageRect( displayGroupTmp, "images/slice.png", circleSize/2, circleSize*1.5/2 )
    background.anchorX = 0
    background.anchorY = 0.66
    background.x = Constants.screenX/2 + deltaX
    background.y = Constants.screenY/2 + deltaY
    background:setFillColor( color[1], color[2], color[3] )
    -- setting mask of an object to identify the true bounding of the background
    local mask = graphics.newMask( "images/sliceMask.png" )
    -- mask.anchorX = 0
    background.maskX = background.x
    background.maskY = background.y
    background:setMask( mask )
    background.maskScaleX, background.maskScaleY = 0.38,0.38
    background.isHitTestMasked = true