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

我正在使用Corona创建一个游戏,其中动物从屏幕顶部掉落并不断反弹。当您点击动物时,它会消失。

我已经像画圆一样绘制了所有的动物,然后给它们添加了一个圆形的物理体。这些图像是带有透明度的PNG图像。

问题是,一些动物的细节,比如耳朵和爪子,它们在物理体范围之外(这是我想要的,因为这样碰撞效果更好)。此外,当我点击动物图像外部时,有时它会被按在我的图像的alpha区域上,被算作一次点击,但我实际上并没有点在动物上。

我希望只有在我点击其物理体区域时才会消失。

有谁知道该如何处理吗?有没有一种方法为物理体添加触摸处理程序?(碰撞效果非常好,只是当与图像相关的触摸而不是物理体时存在问题)。

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);
点赞
用户2376323
用户2376323

这是因为图像空间是矩形的。请在你的动物对象上使用 MASK,并打开命中测试选项(true)。

点击此链接以了解更多有关图像遮罩的信息

下面是一个例子:

local displayGroupTmp = display.newGroup( )
    displayGroupTmp.id = id + 1
    -- 创建一个圆片
    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] )
    -- 设置一个对象的掩模,以确定背景的真实边界
    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
2015-05-23 18:30:48