Explanation:
I have to start with a disclaimer: this is memory and CPU intensive. By its very nature, it’s bound to use a solid amount of memory and CPU, but I’ll admit I didn’t even try to compress or optimize that heavily. I got kinda burned out on this project, so I’ve gotten it to a functional state and I’m releasing it so I can move on. Coronavirus quarantine has taken my motivation away, sorry.
This module is used to record and replay moments of your game inside a ViewportFrame. You can tell it what objects to record, such as the players and ball, and what objects to display statically, such as the map and props. It’s a pretty powerful module that extends a lot of functionality to the user, so you can create entire viewing systems with all the features of a standard player of an MP4.
The module stores frame deltas and creates interpolated frames, so even if your game lag or frame drops during recording, it’ll be played back perfectly smooth and timed correctly. This also means that slow motion is still buttery smooth.
You can record at 10 FPS but it’ll always playback 60 FPS (or whatever you’re getting) and just create the assumed frames in between.
This module has not been tested that extensively, so let me know if you find any issues.
Demonstration:
(This demo uses the “Follow” camera type)
Here’s the place uncopylocked. A lot of the demo is messy and bad practice, but I wanted to put something together quickly so you can see what it’s capable of. It’s not a real soccer game, so don’t try to take that aspect of it!
API Documentation:
[function] Replay.new(Settings)
Returns a new ReplayObject
@param [table] Settings
[number] Settings.FPS
The FPS to record at
defaults to 20
[string] Settings.CameraType
The type of camera for the Replay object playback
("Recorded", "Track", "Follow", or "Custom")
defaults to "Recorded"
[Vector3] Settings.CameraPosition
Where the camera should sit during playback
Only relevant when set to "Track"
[Instance] Settings.CameraSubject
Not relevant to "Recorded"
[Instance] ReplayObject.VPF
The ViewportFrame for you to parent to your desired GUI
[Instance] ReplayObject.Camera
The Camera (use only if CameraType is set to "Custom")
[function] ReplayObject:Register(Object, IgnoreDescendants)
Adds Object to be recorded for playback
@param [Instance] Object
The object to register for recording
@param [Boolean] IgnoreDescendants
Whether or not it should recursively register the entire object (useful for models and folders)
defaults to false
[function] ReplayObject:RegisterStatic(Object, IgnoreDescendants)
Adds Object to be displayed during playback without moving or recording (Useful for map and props)
@param [Instance] Object
The object to register for static display
@param [Boolean] IgnoreDescendants
Whether or not it should recursively register the entire object (useful for models and folders)
defaults to false
[function] ReplayObject:StartRecording(MaxRecordingTime)
Begins recording all registered objects
@param [number] MaxRecordingTime
How long the recording can be before automatically stopping
defaults to 30
[function] ReplayObject:StopRecording()
Stops the in-progress recording , and prepares the playback functions
[function] ReplayObject:ClearRecording()
Clears the stored recording to allow another to be recorded without needing a new ReplayObject and registering everything again
[function] ReplayObject:Destroy()
Empties the ReplayObject and associated objects for GC
[function] ReplayObject:Play(PlaySpeed,StartTime,Override)
Plays the stored recording in the ViewportFrame
@param [number] PlaySpeed
The time multiplier (useful for slow motion replays or sped up recaps)
defaults to 1
@param [number] StartTime
The time at which playback should begin
defaults to 0
@param [Boolean] Override
Wether or not this playback should override any in-progress playback
defaults to false
[function] ReplayObject:Stop()
Halts any in-progress playback
[function] ReplayObject:GoToTime(Time)
Displays the state in the stored recording in the ViewportFrame at the given Time
@param [number] Time
What time in the recording to render
[function] ReplayObject:GoToPercent(Percent)
Displays the state in the stored recording in the ViewportFrame at the given Percent
@param [number] Percent
What percent of the way through the recording to render
[function] ReplayObject:GoToFrame(Frame)
Displays the state in the stored recording in the ViewportFrame at the given Frame
@param [number] Percent
What frame of the recording to render
[event] ReplayObject.RecordingStarted
Fires when a recording starts
[event] ReplayObject.RecordingStopped
Fires when a recording stops
[event] ReplayObject.FrameChanged
Fires when the rendered frame of the recording changes
@arg [number] Frame
What frame is now being rendered
@arg [number] Time
What time is now being rendered
@arg [number] Percent
What percent is now being rendered
[property] ReplayObject.Playing
Read only boolean of the playing state
[property] ReplayObject.Recording
Read only boolean of the recording state
[property] ReplayObject.Recorded
Read only boolean whether there is a stored recording
[property] ReplayObject.FrameCount
Read only number of how many frames are in the stored recording
[property] ReplayObject.RecordingTime
Read only number of how long the stored recording is (in seconds)
Module:
Final notes
It doesn’t support humanoid clothing wrapping because that’s a pain in the neck to deal with.
Update 1.1 has added humanoid support. Read here: VPF Replay Module - #12 by boatbomber
I’m considering a ReplayObject:Serialize()
and ReplayModule.fromSerial(SerializedReplay)
so that replays can be saved, but that’s a lot of work and compression so maybe later.