Reputation: 9753
Inside a loop I change the text of a textfield. But corona does not render until the loop is finished. Is it possible to force a render inside a loop?
I have tried with display.setDrawMode( "forceRender" ) and to do a sleep in the loop but it does not matter. Im trying to do a progressbar that updates.
Upvotes: 1
Views: 352
Reputation: 29493
Corona only renders between your event handlers. While your handler loops, Corona cannot update the display. Basically all commands in your handler than affect the display take effect only after the handler returns control to Corona. So if you want to show a value change repeatedly in a text field, you can't use a loop, only last change to the value will be visible on display, and only after return.
Therefore, you need to use one of Corona's mechanisms to cause the update to occur again. For example, you could listen for Runtime
's enterFrame
event; in there, determine if it is time to update the value and/or the text field and act accordingly. If this leads to too many updates (it will be 30 or 60 times per second), then another way would be to schedule an update of text field for later, as suggested by Frozire:
function updateValueDisplayed()
...compute new value...
...if changed, update the display object that shows the value...
end
timer.performWithDelay( 500, updateValueDisplayed, -1 )
The above will call updateValueDisplayed
twice per second, until you exit. If the delay should be different every time, or should stop under certain conditions, then you could performWithDelay
only once (remove third call parameter) and call timer.performWithDelay( delay, updateValueDisplayed)
from within updateValueDisplayed
as appropriate.
Clarification: you can't use a for
loop. You can only use a repeated function call, two ways are described above.
Upvotes: 2