Screen recording in scene
It is possible to record a scene, or a Node and its descendants? I know you can access a Texture object of a Node, but this object appears to be uneditable, and un-transferable to either pixel data or to write to a file.
This post is deleted!last edited by zipit
Record as a still image or as a video?
Ah thank you, this could work! As long as it's fast enough to work every frame... I could of course just slow it down.
draw_snapshotmethod is fine for static screenshots, but not nearly fast enough to record video.
You can use
objc_utilto bridge the native ReplayKit framework. Here's a demo of that. It includes a very simple scene with some rotating space ships, just to have something to record... In this example, the recording is started in the scene's
setupmethod, and stopped in its
stopmethod (which is called automatically when the scene is about to be closed).
from objc_util import * from scene import * import random load_framework('ReplayKit') RPScreenRecorder = ObjCClass('RPScreenRecorder') def previewControllerDidFinish_(_self, _cmd, _vc): ObjCInstance(_vc).dismissViewControllerAnimated_completion_(True, None) PreviewDelegate = create_objc_class('PreviewDelegate', methods=[previewControllerDidFinish_]) def stop_callback(_cmd, _vc): vc = ObjCInstance(_vc) delegate = PreviewDelegate.new().autorelease() vc.setPreviewControllerDelegate_(delegate) rootvc = UIApplication.sharedApplication().keyWindow().rootViewController() vc.popoverPresentationController().setSourceView_(rootvc.view()) rootvc.presentViewController_animated_completion_(vc, True, None) stop_handler = ObjCBlock(stop_callback, restype=None, argtypes=[c_void_p, c_void_p]) recorder = RPScreenRecorder.sharedRecorder() @on_main_thread def start_recording(): recorder.startRecordingWithMicrophoneEnabled_handler_(False, None) @on_main_thread def stop_recording(): recorder.stopRecordingWithHandler_(stop_handler) class MyScene (Scene): def setup(self): start_recording() for i in range(25): s = SpriteNode('spc:PlayerShip2Orange', position=(random.uniform(0, self.size.w), random.uniform(0, self.size.h)), parent=self) s.run_action(Action.repeat(Action.rotate_by(1, random.uniform(0.2, 0.8)), 0)) def stop(self): stop_recording() run(MyScene())
awsome! thanks for this example.