record player replays from just inputs?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • For an arcade game, I want to have it so you can download replays from the high score table.

    From what I've seen, replays normally just record player input button presses. This makes a nice small replay file.

    But this is only possible if you're doing a fixed framerate, like 60 FPS. Otherwise if someone has a different framerate, the timing of the inputs will vary and the playback will desync, breaking the replay.

    C3 forces delta time and vsync, so we can't do a fixed frame rate.

    I thought maybe I could just record the game at 30 fps, taking full snapshots of every object position, recording the game like a video. Similar to the follow behavior, but for everything. But for a 25 minute game, this kind of data would be huge, many megabytes, and I'm not sure if that's a good option?

    Does anyone have any general idea for how to do a replay system that's possible in C3? Preferably lightweight.

    thanks

  • 25 minutes is a long time to have a replay! Perhaps a video recording would do the job? Saving positions every frame possibly isn't actually that bad - many megabytes of JSON data is not that heavy for most systems and should compress well too. Otherwise perhaps the Follow behavior would help. It can do record and replay and you can choose a lower history rate - which defaults to 30 FPS - to limit the amount of data saved, and it uses interpolation to smooth movement through the saved entries. I don't think it will do everything, but it sounds like it does a lot of what you need.

  • If you ran your game logic at a fixed rate you could do that.

    One way to do that is to accumulate dt and once it’s big enough do the logic for a frame. So say try to run at 30fps:

    var t=0 
    Every tick 
    — add dt to t 
    While  
    t>=1/30 
    — subtract 1/30 from t 
    — do all game logic for a frame here

    We are still limited by the screen’s refresh rate so even though the game is running at a fixed rate the frames will have to snap to the closest actual frame. The above is a simple example but may need some tweaking to ensure the frames are evenly spaced otherwise it looks janky. As a side effect of that, the jank can be much worse depending on the refresh rate.

    One possible tweak could be to compare t<1/30-0.1 or something to smooth out the variances of frame times. But that magic number kinda relates to what the actual refresh rate is. Another idea could be to skip frames evenly and just allow the game to run slower or faster, but results may vary. Part of the issue with improved tweaking you’d need to know the actual screen refresh rate, but that can only be found experimentally and approximately.

    To avoid the jank you could also keep track of the all the state of the objects on the current and previous frames and interpolate between them to give smooth motion. But realistically you’d need to simulate a frame in advance so you’d have a one frame of input delay. And I’m talking a frame at the fixed timestep. Plus doing this is rather laborious to do with a lot of objects.

    Anyways, the main drawback to this is having to implement all logic under that event. You wouldn’t be able to utilize behaviors, and likely not be able to use input triggers. Basically you’d not be able to use all construct features when doing this.

    However, that would allow you to save replays just as inputs that you could playback.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • thanks guys for the thoughts!

    I've done some experimentation, found that I can record data every frame at 60fps (every "1/60" seconds). Putting the player position, animation & frame, and scrolling position, into a string.

    And in 25 minutes it only uses 1mb (compressed).

    Which seems like it will hopefully be small enough. And it has the upside of being accurate and smooth at various framerates.

    Although, I now need to record enemies and all the bullets. But if the enemies are on set paths and the bullets are linear, maybe I could just record when they're created & destroyed.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)