简体   繁体   中英

Corona, transition.to upon removal from table

Using Corona, i would like to move object when i delete it from a table. The problem is that i iterate the table on every frame. When x > WIDTH - 50 i would like for the monkey to stop moving in a sinuswave form and jump into the removeMonkeys function.

My Code:

local function removeMonkeys(obj)
    transition.to(obj, {time = 1500, y = 2*HEIGHT/3, onComplete = obj:removeSelf()})
    numMonkeys = numMonkeys - 1;
end   
function startGame() 
    timer.performWithDelay(500, spawn, maxNumMonkeys)
    local function onEveryFrame( event )
    for i = 1, #monkeySet do
        if(monkeySet[i] ~= nil) then 
            monkeySet[i].x = monkeySet[i].x + 2
            monkeySet[i].y = monkeySet[i].y + math.sin(monkeySet[i].x/monkeySpeed)*Amplitude/5
            if(monkeySet[i].x > WIDTH -50) then
                removeMonkeys(monkeySet[i])
                table.remove(monkeySet, i)
                print(#monkeySet)
            end
        end
    end
end 
Runtime:addEventListener( "enterFrame", onEveryFrame )

Is there anything I'm missing here?

不确定您在这里问的是什么,但是如果您的transition.to不起作用,请检查您是否在执行时杀死了对monkeySet [i]的唯一引用

table.remove(monkeySet, i)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM