[英]Corona SDK - touch transparency issue. Event on physics body?
新手在這里! :P
我正在嘗試在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);
這是由於矩形圖像空間。 嘗試在動物對象上使用MASK,並在(true)上啟用HIT TEST選項: 嘗試使用此鏈接遮罩圖像
這是一個例子:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.