Faster touch

Jimmy

Active Member
Tutorial Author
Joined
Jan 2, 2020
I'm dealing with making a mini-game in my lemming clone that allows the player to click a button let's say 10 times as fast as he/she. So I want to measure the time between touch 1 and touch 2 etc and store the times.

However I'm not sure how to do this?

Could you perhaps use touch events? Currently I use touch x/y/down commands inside OnRender and poll the raw touch information. I'm not sure that this is the best place to place, It seem slow compared to other reaction games that I've had experience with, so I know there's a better way. :(

But that's where I am right now. I'm now thinking of trying to set OnUpdate to be 120 hz and move allt the touch commands into that part of the program.

Does anyone know how to solve this problem?
 

Jimmy

Active Member
Tutorial Author
Joined
Jan 2, 2020
I made a test for that idea and it did not seem to work.

As a test I try to read the touch 10 times and count the number of times it's uniqe, in each OnUpdate (which is to 120hz in this case).

But the counter is never higher than 1 unique read...

Any ideas how to improve the speed a bit more?

Android touch speed test:
Import mojo.app
Import mojo2

Function Main()
    New MyApp
End

Class MyApp Extends App

    Field counter:Int
    Field counter2:Int
    Field canvas:Canvas
    Field x:Int[1000]
    Field y:Int[1000]
    Field index:Int
    Field mx : Int
    Field my : Int
    Field ox : Int
    Field oy : Int
    
    Method OnCreate()
        SetUpdateRate 120
        SetSwapInterval = 1
        canvas = New Canvas()
    End
    
    Method OnUpdate()
    
    counter=counter+1
    
    ' This loop tries to read touch information 10 times each 120hz (Works only on Android as HTML has a maximized onUpdate of 60 fps like OnRender)
    For Local temp := 0 To 10
    
        ox = mx
        oy = oy
        mx = TouchX(0)
        my = TouchY(0)
        If (mx <> ox) And (my <> oy)
            x[index] = mx
            y[index] = my
            index = index + 1
        Endif
        
    Next
        
    End
    
    Method OnRender()
            
        counter2=counter2+1
        canvas.Clear
        canvas.DrawText " UPDATECOUNTER = "+counter/60+" RENDERCOUNTER = "+counter2/60,0,0
        canvas.DrawText " Index this screen update = " + index,0,20
        index = 0
    
        canvas.Flush
    End
    
End
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Did you try using the amount of hits per frame of TouchHit() ?
This is not what you asked for, but maybe good enough for practical use as you can visualize the hit count only once per frame!?
Cerberus X:
Import mojo.app
Import mojo2

Function Main()
    New MyApp
End

Class MyApp Extends App

    Field counter:Int
    Field counter2:Int
    Field canvas:Canvas
    
    Field hit:Int
    
    Method OnCreate()
        SetUpdateRate 3 ' -------------->>>> This is just to clearly show the difference if your clicking speed is slow ;-)
        SetSwapInterval = 1
        canvas = New Canvas()
    End
    
    Method OnUpdate()
    
        hit = TouchHit()
        
        If hit>0
            counter = counter + hit
            counter2 = counter2 + 1
        Endif
        
    End
    
    Method OnRender()
            
        
        canvas.Clear
        canvas.DrawText " MultipleHitCnt =  "+counter+" OneHitPerFrameCnt "+counter2,0,0
    
    
        canvas.Flush
    End
    
End
 

Jimmy

Active Member
Tutorial Author
Joined
Jan 2, 2020
It works on low 3 frames which is great. But Hit only gives the number of hits since the last frame? What if I need the x & y for all those hits between the each frame that you read? Are they also stored somewhere becuase I cannot use TouchX to read those retrospectively in the same way as Hit gives you the number of hits?
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
For some use cases you could just interpolate the x y coords from two frames to get a higher resolution, but if your want something like alternating fingers touching two buttons this wouldn't work.

I don't know if mulitple hit coords are stored somewhere, but I am pretty sure you cannot access them directly from within cerberus.
 

Jimmy

Active Member
Tutorial Author
Joined
Jan 2, 2020
Thanks so much, will try that. In case it does not work I might check in the source and see if I can save the x & y coord with each click as the number of hits are saved already hopefully it shouldn't be too hard.

But if one increase from 3 fps to 60 fps you will always get the same number on both parameters, so your test prooved a good point!
So there might not be any more touch events to collect, they must using some algorithm instead. Interpolation or something like you said. Thanks again!
 

Jimmy

Active Member
Tutorial Author
Joined
Jan 2, 2020
Is there a possibility to get exact timetags when something happened? That would make it possible to improved the interpolation
 
Top Bottom