Also, is there a test to determine whether an object exists? I’m getting a few errors from trying to remove an object that’s already been removed. [import]uid: 1560 topic_id: 2123 reply_id: 6349[/import]
Turning an object invisible (setting alpha to 0) doesn’t free up the memory used by the object. You need to object.removeSelf() to free up the memory.
If you set an object to nil after removing it, you can check for nil later to detect if it’s been removed. (You don’t need to set the object to nil after freeing the object to remove the texture memory used by the object.)
Thanks, so is
[lua]transition.to(msg, {time=3000, alpha=0, onComplete=remove:self()}[/lua]
the right way to do that?
It seems I can’t put object.removeSelf() in a separate line after the transition because it will remove the object before the transition is complete. [import]uid: 1560 topic_id: 2123 reply_id: 6355[/import]
You can remove the object after the transition using:
transition.to( msg, {time = 3000, alpha = 0}, function() msg.removeSelf() end )
All display and timer functions happen after the “chunk” executes so any lines after the transition.to will happen before the transition starts. If you need something delayed you would use another transition.to or a timer.performWithDelay method and with the onComplete set to the method you want to execute after the delay.
I’m trying the above code to display a score message and not finding much success. If I set the finish alpha on the transition to something like .75 the message is never destroyed. Is there something I’m missing?
[code]
function dispDestroyedEnemy( xPos, yPos, addScore)
local tempScore = ui.newLabel{
bounds = { display.contentWidth - 300, 10, 100, 24 }, – align label with right side of current screen
text = “” … addScore,
font = “Trebuchet-BoldItalic”,
textColor = { 255, 225, 102, 255 },
size = 32,
align = “right”
}
tempScore.x = xPos
tempScore.y = yPos
transition.to( scoreDisplay, {time = 3000, alpha = 0.0}, function() scoreDisplay.removeSelf() end )
end
[/code] [import]uid: 5641 topic_id: 2123 reply_id: 6373[/import]
I should probably mention that this code is in an onTouch event and t is a local event target. Is that the problem? (falling out of scope) [import]uid: 8353 topic_id: 2123 reply_id: 6630[/import]
I’ve tried all the above functions and ain all of them the effect is removed before it get animated/transition.
function RemoveObj(self)
local obj=self
print(obj)
obj:removeSelf()
end
transition.to(bollHitt, {time=2600, alpha=0.5, xScale=2, yScale=2, transition=easing.linear, onComplete=RemoveObj(bollHitt)})
The print print(obj) is shown in the terminal as fast as the animation is triggered. Even if i set delay:30000 in the transition the function is triggered when the transition is…
[import]uid: 28895 topic_id: 2123 reply_id: 21917[/import]
It did not the firt 100 times i tried but now it does. Strange. Must have made some changes.
Tanks any how.
Another question
function RemoveObj(self)
local obj=self
obj:removeSelf()
obj = nil
end
If i don’t put obj = nil obj still have a table reference “number”. Does that acclaimer memory? [import]uid: 28895 topic_id: 2123 reply_id: 21941[/import]