我如何隐藏击中猴子的食物

时间:2014-08-30 07:07:10

标签: lua corona

好吧所以我希望每当某种食物击中猴子时,某种食物就会消失

local objects = {
"banana", 
"grape", 
"pineapple", 
"strawberry",
"watermelon", 

}
 local function spawnObject()
    local objIdx = mRandom(#objects)
    local objName = objects[objIdx]
    local object = display.newImage( "images/fruit_" .. objName .. "_100.png" )
    object.x = mRandom(screenLeft+30, screenRight-30)
    object.y = screenTop
    object.rotation = mRandom(-15, 15)
    if objIdx < 4 then
        object.type = "food"
    else it
        object.type = "other"
    end
    physics.addBody(object, "dynamic")
    grassfront320w:toFront()

我尝试添加这行代码,但它出错了

 local function monkeyCollision( self, event )
    if event.phase == "began" then
        if event.target.type == "monkey" and event.other.type == "food" then
            print( "chomp!" )
            Objects.alpha = 0

1 个答案:

答案 0 :(得分:0)

local function monkeyCollision( self, event )
    if event.phase == "began" then
        if event.target.type == "monkey" and event.other.type == "food" then
            print( "chomp!" )
            event.other.alpha = 0