Reputation: 227
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
Upvotes: 1
Views: 1377
Reputation: 1616
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
Upvotes: 3
Reputation: 3063
Corona SDK onComplete parameters expect a function as the parameter, not the results of a function call. You cannot call another function directly as in the:
onComplete = timer.performWithDelay(12000....)
example.
The best way is to create a function that does the work you want to do when complete:
local function handleOnComplete(target)
target:removeSelf()
target = nil
end
transition.to(block[desplazar], {time=14000, alpha=0, onComplete=handleOnComplete } )
The handleOnComplete gets a parameter passed to it which is the object that was transitioning. I don't understand why you want to wait another 12 seconds after the transition is complete to actually remove it. If that's important, you can put a timer in handleOnComplete() to delay the removal a bit.
Upvotes: 1
Reputation: 36007
This will work:
transition.to(block[desplazar], {time=14000, alpha=0, onComplete=function()
timer.performWithDelay(12000, borrado(desplazar),1)
end })
local function borrado(desplazar)
block[desplazar]:removeSelf()
end
Upvotes: 0
Reputation: 80931
You are passing the result of calling borrado(desplazar)
to timer.performWithDelay. You need to pass a function to performWithDelay which will call borrado(desplazar)
when the timer calls the passed function.
Upvotes: 0