I am trying to use mouse-tracking online. My code works well enough that I collect [x,y] coordinates and a tracking timestamp for each trial. However, it seems that I am collecting mouse position and timing data every 50ms, when I think it should be closer to 16-17ms based on my ~58 framerate.
This is the code I am using to log both time and position in each frame:
Do you in general have any advice on whether I should check “Sync timing on screen refresh”? I’ve had a hard time finding clear documentation on what that checkbox does exactly.
Hi @matiasfduque, thanks for the link, I think it means it’s giving the time of the nearest flip rather than just the absolute time, but that has no effect online anyway. Why do you say that the timestamps are off though? Have you tried saving mouse coordinates using psychoJS.experiment.addData() on each frame directly? The way you are infinitely appending to those arrays is a little unsafe and can slow down the code. You can find an example of continuously tracking x, y data in this demo →
Thanks @sotiri ! I didn’t know adding to arrays per frame could cause issues, so I’ll try using your suggested code instead and see what happens. The reason I think something is off with the timestamps is that given my framerate is ~58 Hz, I would expect the position of the cursor to be recorded approx. every 16-17ms (1/58 = .017). Instead, when I calculate the difference in time between frames, it is around .05 = 50 ms. So the cursor is being recorded every 50ms.
Adding to this:
So, using psychoJS.experiment.addData() in the Each Frame tab only saves one final timestamp, rather than array of timestamps, which is what I need. That’s the reason why I initialize and add to those arrays. Any idea why this would be? Or a better way to do this?
Hi @matiasfduque, no problem, performance.now() tells you how many milliseconds have passed since the browser started timing on the document. You can use it to calculate frame deltas for example and it is used internally for clocking in PsychoJS too. You can read more about it below,