Welcome! Log In Create A New Profile

Advanced

best way to re-order objects on each frame

Posted by lucast4 
best way to re-order objects on each frame
June 29, 2020 12:25PM
Hi, if I am writing my own adapter, my understanding is that the order in which objects are displayed depends on the order in which they are created (with most recently created objects being "under" other objects).

The problem is that on each frame I would like to create new objects that go on top of the older objects. I have implemented this in the following way:
On draw() for each frame, I destroy all objects then recreate them in the desired order.

I find, however, that destroy takes a lot of time (using tic-toc), and now many frames are skipped.

Is there a better way to reorder objects on each frame?
Thanks!
Re: best way to re-order objects on each frame
June 29, 2020 06:28PM
You should explain what the stimulus you want to present looks like, not how you coded it. Your approach may not be appropriate for the stimulus, but, without knowing what you try to achieve by doing so, it is difficult to suggest an alternative or a workaround.
Re: best way to re-order objects on each frame
June 30, 2020 04:26AM
I am trying to leave a trail of little circles (let's say with color A) wherever the animal has touched. Those circles should be on top of the stimuli present at the start, which includes, for example, a line of circles (with color cool smiley.

One option would be to create the circle trail at trial onset, before making the stimulus circles. But the difficulty is that I don't know how many circles will be needed. Maybe the best solution is to create more circles than will be needed, and then on each frame "activate" circles as needed?
Re: best way to re-order objects on each frame
June 30, 2020 01:20PM
Put the following line at the beginning of your timing script. If you don't have mglreverserendering in your mgl directory, please update your NIMH ML.
mglreverserendering(true);  % draw most recently created objects on top of others
Re: best way to re-order objects on each frame
July 04, 2020 12:35PM
Amazing! I can't believe I did not see this. Thanks

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.