LibGDX - Making deathcam for game

Currently I’m trying to make deathcam for my game.
When players are dead, I’d like to show them what happened 2~3 seconds before their death

I tried using ScreenUtils.getFrameBufferPixels to take screenshot and use those image as deathcam.
It sorta works but performance is terrible.
Also if I want to draw image as original size, I need to scale Image again.

So I’m trying to get image other way around.
I searched about it and I think i could use framebufferobject but wiki says
“rendering to them every frame, may not lead to the best performance.”
But as I don’t know when player will die, If i want to use framebufferobject I need to render every frame with it.

Is there any other better way to do it? like getting image directly from batch before flushed?.

Wow… I didn’t ever expect that someone could think about this kind of solution for this problem. It hits performance so hard.

The best (and normal I think) way for implementing it is to design your app for memento.

If you for example design your game’s timeline as reacting for business logic events, you can go back in time and replay saved events. That’s how replays are implemented. I hope it helped you :slight_smile:

PS. you can also record state of the world in keyframes and interpolate or just record it each frame but… it’s not that efficient as event sourced. Or maybe record changes (like git commits).

Thanks for your reply!
So Memento pattern is basically save past variables that needs to recreate same event in object and when replay is needed use saved data to recreate those object and run game normally to show what happened right?

But, to recreate event for user controlled object, I think I need to record all user input frame by frame. Is it a okay way to do it? or is there better way for it?

Depends on your architecture. Best way is designing your software to be event driven:

So for example you don’t record user controlled object transitions each frame but only events that made transition happen
(CharacterStartedMoving(from, direction, timestamp), CharacterStoppedMoving(timestamp), CharacterAttacked(direction, weapon, timestamp) etc.) So you can replay it.

This approach is often used in networking to minimalize size of payload sent over the wire.

Thanks! Now I know what I gotta do. Cool guy like you really help noob like me keep on going!

Np :slight_smile: