I’m trying to create an experiment that involves a continuously rotating (animated) polygon. I’ve made a triangle polygon in the Builder, and added a custom code component (see picture) that adds 1 degree to the orientation of the polygon for each frame. This works perfectly offline, but when I upload the experiment to Pavlovia, it doesn’t rotate anymore and just shows a static picture of a triangle. I don’t get any error messages.
Some things I’ve tried to fix it:
Tried different browsers.
Set the orientation of the polygon to “set every frame” in the Builder. This however also causes it to stop rotating offline, so I keep it set to “constant.”
Tried the code component with different polygons, of different sizes, and with images. They all rotate offline, but not online.
What does polygon.setOri(1,’+’) mean? Try polygon.setOri(t)
Why do you have polygon.draw()? Your first line suggests that polygon is a component in the current routine and will therefore be autodrawn once started.
Please do bookmark my crib sheet, if you haven’t already found it.
I removed it. After reading your crib sheet, I now understand that was redundant. Thank you for that. I’m quite new to programming and I’m learning as I go (that crib sheet is a great help!).
What does polygon.setOri(1,’+’) mean?
It adds 1 degree to the orientation of the polygon each frame. I had written it like that because the next step for my experiment is to change the “1” to a custom value that a participant can change with a key press. So eventually, the code would be something like setOri(customvalue, ‘+’) where customvalue is defined as the number of key presses.
Try polygon.setOri(t)
I uploaded the polygon with this code component instead, and now it does move! However, it moves extremely slowly, I think it would take several minutes to just complete one rotation. It also moves counterclockwise online, whereas offline it moves clockwise. And also, with this setup, I don’t think I could implement the step I mentioned above? Is there any way around that?
But now that my stimulus is rotating I already ran into another problem… I want participants to be able to speed up or slow down the rotation speed by pressing the “up” or “down” arrows on their keyboards, so I added this code:
if polygon.status == STARTED:
thisOri += newOri
polygon.setOri(thisOri)
if event.getKeys('up'):
newOri += 1
if event.getKeys('down'):
newOri -= 1
thisOri and newOri are both defined in the “Begin Experiment” tab as “0.” Again, it works beautifully offline, but doesn’t work online. I’ve read that the “event.getKeys()” part needs to be replaced by “psychoJS.eventManager.getKeys()” when converting to javascript, but when I do this my stimulus does not respond to any key inputs at all.
I guess that’s a whole new issue altogether, and requires some more research!