button press delay. help

i have attack button that has “touch” event. The problem is my object always attacking when i touch attack button without delay.

how to perform delay like 1 second everytime after i touch the button??

use 

timer.performWithDelay(..)

@intxx80 : its doesnt work sir, i still can touch it rapidly :frowning:

Show your code. 

here my code…

[lua]

function serang:touch( event )
 if event.phase=="began"then

  local efek = display.newImageRect(“images/efek.png”, 300,150) 
   physics.addBody( efek, “dynamic”, { friction=0.3, shape=efekShape }  )
   efek.x = made.x
   efek.y= made.y
   transition.to (efek, {time=500, alpha=0})
   camera:add(efek,3,false)
        efek.gravityScale = 0
        efek.isSensor = true
        efek.type = “efek”
        efek.collision=efekCollision
       efek:addEventListener(“collision”, efek)

  made:setLinearVelocity(200,0)
  made:setSequence(“tendang”)
  made:play()

   else
   if event.phase==“ended” then
 

end

end
end
serang:addEventListener(“touch”, serang)

[/lua]

Why you do not use timer.performWithDelay function as @intxx80 suggested? 

First put all of your attack code in a function:

function attack() end

And on your phase == began put the timer.performWithDelay.

use 

timer.performWithDelay(..)

@intxx80 : its doesnt work sir, i still can touch it rapidly :frowning:

Show your code. 

here my code…

[lua]

function serang:touch( event )
 if event.phase=="began"then

  local efek = display.newImageRect(“images/efek.png”, 300,150) 
   physics.addBody( efek, “dynamic”, { friction=0.3, shape=efekShape }  )
   efek.x = made.x
   efek.y= made.y
   transition.to (efek, {time=500, alpha=0})
   camera:add(efek,3,false)
        efek.gravityScale = 0
        efek.isSensor = true
        efek.type = “efek”
        efek.collision=efekCollision
       efek:addEventListener(“collision”, efek)

  made:setLinearVelocity(200,0)
  made:setSequence(“tendang”)
  made:play()

   else
   if event.phase==“ended” then
 

end

end
end
serang:addEventListener(“touch”, serang)

[/lua]

Why you do not use timer.performWithDelay function as @intxx80 suggested? 

First put all of your attack code in a function:

function attack() end

And on your phase == began put the timer.performWithDelay.