Wierd Timer isseus

Started by Gijsdemik, October 20, 2023, 15:26:45

Previous topic - Next topic

Gijsdemik

Hey all,
I am here once again whit a strange qeustion. yes i fixed the last bugs whit your help!
here is my isseu i am trying to create a one time animation effect. the drawtext is just here to test.
if i can get it to work i wil add my image array and drawwimage functions.
The thing is it wont display grapics while counting only when its on its max it show the drawtext for a short time
here is my code

Function Doanimations()
Local animationTimer:TTimer
animationTimer = CreateTimer(6) ' 100 milliseconds between frames
Local Frm:Int
Local Z:Int
Repeat
    If TimerTicks(animationTimer) >= 0 And TimerTicks(animationTimer) < 8
Print + TimerTicks(animationTimer)
DrawText "Test " + TimerTicks(animationTimer)  ,200,200 'replace whit image
   End If
If  TimerTicks(animationTimer) > 8 Then StopTimer(animationTimer)



Until KeyHit(KEY_ESCAPE) Or AppTerminate() Or TimerTicks(animationTimer) >8

EndFunction

I understand to display an image animation i would need to add more then this.
what i am trying to do is get the timerticks clock counter as a frame number for my image.
then i can add max frames and positions. i already have an array whit pictures and maximum frames.
if this works i can add the picture number i need and its max frames.

what i dont really understand is that it counts until its max and then displays the drawtext.
even tou the drawtext is setup to alwayse show in the loop

I tried it in and out of the game loop i got the same results.
hope you guys know whats wrong



Midimaster

#1
You need to put any Draw...() function outside the If time whatever branches.

And graphic-related thing need to be always followed by a FLIP command, before you change the graphic thing to the next stage. This means, that a time-dependent graphic animation cannot processed within a sub-loop like you did it in your example code. Each frame needs to be followed by a FLIP (to get visible). And as we should only use one FLIP per app, the animation cannot be in a second deeper Repeat/Until-loop


Minimalistic code:
Global Time:Int, FrameNr:Int
Repeat
    Cls
    If  Time<MilliSecs()
        Time = MilliSecs()+ 500 'msec
        FrameNr = FrameNr+1
    EndIf    
    DrawText "Test " + FrameNr  ,200,200
    Flip
Until AppTerminate()



Your code would need this form to be runable:

Graphics 800,600
Global AnimationTimer:TTimer = CreateTimer(2) ' 500 milliseconds between frames

Repeat
    Cls
    DoAnimations()
    Flip
Until AppTerminate()

Function DoAnimations()
    If TimerTicks(AnimationTimer) >= 0 And TimerTicks(animationTimer) < 8
        Print  TimerTicks(animationTimer)
        DrawText "Test " + TimerTicks(animationTimer)  ,200,200 'replace whit image
    End If
    If  TimerTicks(animationTimer) > 8 Then StopTimer(animationTimer)
EndFunction

By the way... CreateTimer(6) creates 166 millisecond steps

By the way 2... You cannot observe what happens during a CreateTimer(6) . It's to fast for your eyes. Start testing with CreateTimer(2) to be able to see something

By the way 3... You cannot create the TTimer as LOCAL . This would restart the timer each loop.

By the way 4... You cannot write "Print + TimerTicks(animationTimer)". This Syntax is wrong  (the "+" sign)



I would do it this way:

Runable Example
SuperStrict
Graphics 800,600
Global Time:Int, FrameNr:Int
Repeat
    Cls
    ShowAninamtion()
    If KeyHit(KEY_S) Then FrameNr=0
    DrawText "<S> to restart",100,100   
    Flip
Until AppTerminate()

Function ShowAninamtion()
    If FrameNr>8 Then Return
 
    If  Time<MilliSecs()
        Time = MilliSecs()+ 500 'msec
        FrameNr = FrameNr+1
    EndIf    
    DrawText "Test " + FrameNr  ,200,200
End Function
...back from North Pole.