Search code examples
luacoronasdkcorona-storyboard

Oncomplete its not working in my transition


I have this transition. I want to make a image that is in the block in position "desplazar" dissapear and then delete it.

transition.to(block[desplazar], {time=14000, alpha=0, onComplete=timer.performWithDelay(12000, borrado(desplazar),1) })

local function borrado(desplazar)
    block[desplazar]:removeSelf()
end    

But i'ts not working, the image is dissapearing inmediatly and i think the image is going to to dissapear when the transition is complete, also i have put a delay in the function but it`s not working.

Hope you can help me

Thanks

I made it this way also

transition.to(block[desplazar], {time=14000, alpha=0, onComplete=timer.performWithDelay(12000, intime(),1) })

local function intime()
    print ("intime")
    borrado(desplazar)
end 

Solution

  • this code will work

        local function borrado(desplazar)
            block[desplazar]:removeSelf()
        end 
    
    
    transition.to(block[desplazar], {time=14000, alpha=0, onComplete = timer.performWithDelay(12000, function() borrado(desplazar) end),1})
    

    just remember when using transition and timer do not just call the function with an argument because you will not achieve the time you want it to trigger just like this

     timer.performWithDelay(12000, borrado(desplazar)) 
    

    it will just trigger the function without the time you assign. hope this helps