Create graphics once, then only update them

All the graphics objects (patches, lines and text) are created one time, when the game starts. After that, the render function only changes their data with set:
set(s.hd,'XData',s.DS{k}+DX,'YData',s.DT{k}+G+s.dy)
Creating new objects on every frame is a common reason MATLAB games feel slow. Updating objects that already exist is much cheaper. To hide an object, I set its data to NaN instead of deleting it:
set(s.ho(m),'XData',NaN,'YData',NaN)
David
David on 3 Nov 2026 at 14:10 (Edited on 3 Nov 2026 at 14:29)
For anyone interested, this is @Cephas contest entry to which he is referring to