timer question

Hello
 
I have a button in my app where I want to give the user some feedback, when pressed. I did this with making a small rect-box behind the button, and when the user push the button it gives a little flash.
 
the box is set to Visible = false and gets set to true when the user push the button. 
 
I use performWithDelay to set it back to false and hide the box again after some time.
 
This works… how ever I am wondering if this is the “correct” way. In the corona simulator output, I print the value of the timer. It shows how long time since the last time the user pushed the buttom. I don’t need that and it is a waste of resources for the phone keeping track of that. 

Any tips for doing a delayed task in Lua/Corona?
 
You are velcome to see my code.

local function myTapListener( event ) -- Code executed when the button is tapped local r = math.random(1,126) textBox.text = textString[r] print(r) rect.isVisible = true local function manageTime( event ) rect.isVisible = false print( event.time ) end timer.performWithDelay( 50, manageTime) return true end

I wouldn’t use a timer for this.  I’d use a transition because it is cleaner and safer.

local rect = display.newRect( 10, 10, 100, 100 ) rect.alpha = 0 -- Now to show it for 1/2 second do this transition.cancel( rect ) rect.alpha = 1 transition.to( rect, { alpha = 0, time = 0, delay = 500 } ) Note: The cancel call above is to handle overlapping 'show'.

PS - I know you had 50 ms, but that is super short, so I made it longer in the example to be clear.

Thanks. That works much better.

I had a side problem with my code, that the flash didn’t always fire if the user pressed to quickly again. That seams not to be a problem anymore. 

You’re welcome. Glad that helped.

I wouldn’t use a timer for this.  I’d use a transition because it is cleaner and safer.

local rect = display.newRect( 10, 10, 100, 100 ) rect.alpha = 0 -- Now to show it for 1/2 second do this transition.cancel( rect ) rect.alpha = 1 transition.to( rect, { alpha = 0, time = 0, delay = 500 } ) Note: The cancel call above is to handle overlapping 'show'.

PS - I know you had 50 ms, but that is super short, so I made it longer in the example to be clear.

Thanks. That works much better.

I had a side problem with my code, that the flash didn’t always fire if the user pressed to quickly again. That seams not to be a problem anymore. 

You’re welcome. Glad that helped.