"Tap" Object Makes It Rotate

Hi,

What is the best way to make a Object Rotate when you double tap it?
I can make it rotate nonstop with:

local function rotate (event)
obj.rotation = obj.rotation +2
end

Runtime:addEventListener( “enterFrame”, rotate)

But what I really want is when you double “tap” the object it rotates.
I tried doing things like Runtime:addEventListener(“tap”, rotate")
but nothing happens will anyone point me in the right direction please,
Thank You!
[import]uid: 30314 topic_id: 6574 reply_id: 306574[/import]

Thanks for reply,

I tried the code but it did not work for me
when I touch the object it wont rotate. Is there
a proper way to add a eventListener “tap”
and a function that reads the tap and rotates the
object +1 on each tap or double tap?

Thanks in advance! [import]uid: 30314 topic_id: 6574 reply_id: 23099[/import]

Sorry, I just got home to test my code.

Change “release” to “ended” and it works [import]uid: 6084 topic_id: 6574 reply_id: 23109[/import]

[lua]box=display.newImage(“box.png”)
box.x = display.contentWidth/2
box.y = display.contentHeight/2
lastTouch = 0

function touchAction ( event )
if event.phase == “ended” then
if system.getTimer() - lastTouch < 500 then
– previous touch was within 500 milliseconds
box.rotation = box.rotation + 45
else
– only a single tap or double-tap was too slow
end
lastTouch = system.getTimer()
end
end

box:addEventListener (“touch”, touchAction)[/lua]

I’m doing this off the top of my head, but I think this does it.

(edited and actually tested) [import]uid: 6084 topic_id: 6574 reply_id: 23015[/import]

I manage to make it work by doing the following:

local function rotate (event)
obj.rotation = obj.rotation +5
end

obj:addEventListener(“tap”, rotate)

(it works fine I still have not tried changing “release”
to “ended” so I will go ahead and try that maybe I
get better results but I will like to Thank You
for your help and hopefully this helps out others! [import]uid: 30314 topic_id: 6574 reply_id: 23114[/import]