Loops executed each frame

Hi,

I found that 2 loops are executed each frame on the ‘Main’; they are ‘Draw’ and ‘Touch’; in the ‘Draw’ loop, I call the draw loops of my class / classes which draw the graphics; in the ‘Touch’ loop, i call the touch loop of the class / classes (which need it).

I miss some loops for update (which update logic); I create this loops on my classes (Update), and I call from ‘Draw’ loop of the ‘Main’; It will be great to get another ‘executed each frame loop’ on the ‘Main’ to include the update of logic.

Is there any way to include more ‘executed each frame loop’ on the ‘Main’?

Thanks in advance,

Regards, fjsantos.

Your description of what happens is not quite correct. The touched function is executed once for each touch between each draw call. So there’s only one function that you can rely on being called once each cycle. You could simply add an update function to the draw loop:

function draw()
    update()
    -- draw some stuff
end

function update()
    -- update all stuff
end

Some here like to hide this sort of thing. Put this somewhere where it will be executed after the draw function is defined (could do it in setup, could just do it at the end of the Main tab).

_draw = draw

function draw()
    update()
    _draw()
end

Hi Andrew_Stacey,

Thanks so much for clarify me the ‘draw’ and ‘touch’ loops (it’s great to know really how it works!).

Regarding the ‘update’ loop, i did exactly that, but I think that it will be more clean to get 2 loops (draw & update), independents. (Although I understand that not all people wants to add complexity).

Thanks so much!

Regards, fjsantos.