36 lines
638 B
GDScript
36 lines
638 B
GDScript
extends Node
|
|
class_name PlayerRecorder
|
|
|
|
var replay: ReplayRecording
|
|
var this_frame: int = 0
|
|
var sprite: int = 0
|
|
var player: Node
|
|
var scene: Node
|
|
|
|
export var save_to: String
|
|
export var enabled: bool
|
|
|
|
func _ready():
|
|
if not enabled:
|
|
queue_free()
|
|
|
|
replay = ReplayRecording.new()
|
|
replay.time_per_frame = 1.0 / 30.0
|
|
player = get_parent()
|
|
player.recorder = self
|
|
scene = player.get_parent()
|
|
|
|
func _physics_process(_delta):
|
|
if this_frame == 0:
|
|
this_frame = 1
|
|
replay.positions.append(player.pos)
|
|
replay.sprites.append(sprite)
|
|
replay.frames += 1
|
|
|
|
else:
|
|
this_frame -= 1
|
|
|
|
func save():
|
|
replay.save_to_uri(save_to)
|
|
queue_free()
|