Acceleration of events using timer.performWithDelay

I have encountered a problem using timer.performWithDelay API. 

Generally if one timer.performWithDelay fires an event, this event will develop normally. 

Now, I found something: if in the middle of one event rerun the event … the process is accelerated. And if you ever do it repeatedly, the event is more and more accelerated. 

It is very easy to avoid this. But the problem does not go through there. I know that accelerates, as I like to handle this acceleration in a controlled manner.

Please share some sample code demonstrating the issue, and pose a question.  I’m afraid I didn’t see a clear question there. 

Cheers,

Ed

Vector=display.newRect (512,350,1,50)

Vector:setFillColor( 1, 0, 0 )

Boton=display.newCircle (512,600,20)

Boton:setFillColor( 0, 1, 0 )

A=1

function Rotar (event)

function Actualizar(event)

Vector:rotate(A)

end

timer.performWithDelay( 5, Actualizar,360 )

end

Boton:addEventListener(“tap”, Rotar)

  1. The forum has a code formatting tool.   Be kind and use it in future questions. See the little blue symbol above the editing box (only visible while editing a post):  <> 

    function Rotar (event) function Actualizar(event) Vector:rotate(A) end timer.performWithDelay( 5, Actualizar,360 ) end

  2. Again, no question asked, but I’ll guess.

You wonder why, when you run Rotar(), that ‘Vector’ starts to rotate faster.

Well, you’ve got a function in a function, so when you run ‘Rotar()’ one time you get:

Vector:rotate() … wait 5 ms

Vector:rotate() … wait 5 ms

repeat 360 times

However, if you run ‘Rotar()’ again before 1800ms goes by, you start another sequence on top of the existing one.

If you want to ensure the sequence can’t overlap, do this:

local lastTimer function Rotar (event) function Actualizar(event) Vector:rotate(A) end if( lastTimer ) then timer.cancel(lastTimer) end lastTimer = timer.performWithDelay( 5, Actualizar,360 ) end

-Ed

I do not understand the question. You will have to read the beginning of the post. Sorry for not formatting the text. But I think it was not necessary. It was very simple script. 

Know very well that I do to not accelerate. The question is: Why it accelerate? There would have to accelerate to order him back to start again or start in the middle of the sequence. For what reason would speed? 

I want a technical answer, not a solution. The solution I have since before publishing the post.

RoamingGamer answered your question technically and gave you a solution on top of it.

Or in other words: It is accelerating because the timer is firing its start event before the function-within-function is finished processing.

I appreciate your opinion. But that does not answer the initial question. I know that if shot before the end of the event fires again faster. That I know. So I got the question to the forum. Also how to avoid this happening. I have resolved the question before boarding. The idea is to know how it works at processor level acceleration to take advantage. That’s what interests me. 

A hug.

Please share some sample code demonstrating the issue, and pose a question.  I’m afraid I didn’t see a clear question there. 

Cheers,

Ed

Vector=display.newRect (512,350,1,50)

Vector:setFillColor( 1, 0, 0 )

Boton=display.newCircle (512,600,20)

Boton:setFillColor( 0, 1, 0 )

A=1

function Rotar (event)

function Actualizar(event)

Vector:rotate(A)

end

timer.performWithDelay( 5, Actualizar,360 )

end

Boton:addEventListener(“tap”, Rotar)

  1. The forum has a code formatting tool.   Be kind and use it in future questions. See the little blue symbol above the editing box (only visible while editing a post):  <> 

    function Rotar (event) function Actualizar(event) Vector:rotate(A) end timer.performWithDelay( 5, Actualizar,360 ) end

  2. Again, no question asked, but I’ll guess.

You wonder why, when you run Rotar(), that ‘Vector’ starts to rotate faster.

Well, you’ve got a function in a function, so when you run ‘Rotar()’ one time you get:

Vector:rotate() … wait 5 ms

Vector:rotate() … wait 5 ms

repeat 360 times

However, if you run ‘Rotar()’ again before 1800ms goes by, you start another sequence on top of the existing one.

If you want to ensure the sequence can’t overlap, do this:

local lastTimer function Rotar (event) function Actualizar(event) Vector:rotate(A) end if( lastTimer ) then timer.cancel(lastTimer) end lastTimer = timer.performWithDelay( 5, Actualizar,360 ) end

-Ed

I do not understand the question. You will have to read the beginning of the post. Sorry for not formatting the text. But I think it was not necessary. It was very simple script. 

Know very well that I do to not accelerate. The question is: Why it accelerate? There would have to accelerate to order him back to start again or start in the middle of the sequence. For what reason would speed? 

I want a technical answer, not a solution. The solution I have since before publishing the post.

RoamingGamer answered your question technically and gave you a solution on top of it.

Or in other words: It is accelerating because the timer is firing its start event before the function-within-function is finished processing.

I appreciate your opinion. But that does not answer the initial question. I know that if shot before the end of the event fires again faster. That I know. So I got the question to the forum. Also how to avoid this happening. I have resolved the question before boarding. The idea is to know how it works at processor level acceleration to take advantage. That’s what interests me. 

A hug.